chromium/third_party/flatbuffers/src/src/util.cpp

/*
 * Copyright 2016 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// clang-format off
// Dont't remove `format off`, it prevent reordering of win-includes.

#include <cstring>
#if defined(__MINGW32__) || defined(__MINGW64__) || defined(__CYGWIN__) || \
    defined(__QNXNTO__)
#define _POSIX_C_SOURCE
#define _XOPEN_SOURCE
#endif

#if defined(_WIN32) || defined(__MINGW32__) || defined(__MINGW64__) || defined(__CYGWIN__)
#  ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#  endif
#  ifndef NOMINMAX
#define NOMINMAX
#  endif
#  ifdef _MSC_VER
#    include <crtdbg.h>
#  endif
#  include <windows.h>  // Must be included before <direct.h>
#  ifndef __CYGWIN__
#    include <direct.h>
#  endif
#  include <winbase.h>
#  undef interface  // This is also important because of reasons
#endif
// clang-format on

#include "flatbuffers/util.h"

#include <sys/stat.h>

#include <clocale>
#include <cstdlib>
#include <fstream>
#include <functional>

#include "flatbuffers/base.h"

namespace flatbuffers {

namespace {

static bool FileExistsRaw(const char *name) {}

static bool LoadFileRaw(const char *name, bool binary, std::string *buf) {}

LoadFileFunction g_load_file_function =;
FileExistsFunction g_file_exists_function =;

static std::string ToCamelCase(const std::string &input, bool is_upper) {}

static std::string ToSnakeCase(const std::string &input, bool screaming) {}

std::string ToAll(const std::string &input,
                  std::function<char(const char)> transform) {}

std::string CamelToSnake(const std::string &input) {}

std::string DasherToSnake(const std::string &input) {}

std::string ToDasher(const std::string &input) {}

// Converts foo_bar_123baz_456 to foo_bar123_baz456
std::string SnakeToSnake2(const std::string &s) {}

}  // namespace

bool LoadFile(const char *name, bool binary, std::string *buf) {}

bool FileExists(const char *name) {}

bool DirExists(const char *name) {}

LoadFileFunction SetLoadFileFunction(LoadFileFunction load_file_function) {}

FileExistsFunction SetFileExistsFunction(
    FileExistsFunction file_exists_function) {}

bool SaveFile(const char *name, const char *buf, size_t len, bool binary) {}

// We internally store paths in posix format ('/'). Paths supplied
// by the user should go through PosixPath to ensure correct behavior
// on Windows when paths are string-compared.

static const char kPathSeparatorWindows =;
static const char *PathSeparatorSet =;  // Intentionally no ':'

std::string StripExtension(const std::string &filepath) {}

std::string GetExtension(const std::string &filepath) {}

std::string StripPath(const std::string &filepath) {}

std::string StripFileName(const std::string &filepath) {}

std::string StripPrefix(const std::string &filepath,
                        const std::string &prefix_to_remove) {}

std::string ConCatPathFileName(const std::string &path,
                               const std::string &filename) {}

std::string PosixPath(const char *path) {}
std::string PosixPath(const std::string &path) {}

void EnsureDirExists(const std::string &filepath) {}

std::string FilePath(const std::string& project, const std::string& filePath, bool absolute) {}

std::string AbsolutePath(const std::string &filepath) {}

std::string RelativeToRootPath(const std::string &project,
                               const std::string &filepath) {}

// Locale-independent code.
#if defined(FLATBUFFERS_LOCALE_INDEPENDENT) && \
    (FLATBUFFERS_LOCALE_INDEPENDENT > 0)

// clang-format off
// Allocate locale instance at startup of application.
ClassicLocale ClassicLocale::instance_;

#ifdef _MSC_VER
  ClassicLocale::ClassicLocale()
    : locale_(_create_locale(LC_ALL, "C")) {}
  ClassicLocale::~ClassicLocale() { _free_locale(locale_); }
#else
  ClassicLocale::ClassicLocale()
    : locale_(newlocale(LC_ALL, "C", nullptr)) {}
  ClassicLocale::~ClassicLocale() { freelocale(locale_); }
#endif
// clang-format on

#endif  // !FLATBUFFERS_LOCALE_INDEPENDENT

std::string RemoveStringQuotes(const std::string &s) {}

bool SetGlobalTestLocale(const char *locale_name, std::string *_value) {}

bool ReadEnvironmentVariable(const char *var_name, std::string *_value) {}

std::string ConvertCase(const std::string &input, Case output_case,
                        Case input_case) {}

}  // namespace flatbuffers