Repository: google/flatbuffers
File: include/codegen/namer.h (C/C++)

Code before:

  // Formats `directories` prefixed with the output_path and joined with the
  // right seperator. Output path prefixing and the trailing separator may be
  // skiped using `skips`.
  // Callers may want to use `EnsureDirExists` with the result.
  // input_case is used to tell how to modify namespace. e.g. kUpperCamel will
  // add a underscode between case changes, so MyGame turns into My_Game
  // (depending also on the output_case).
  virtual std::string Directories(const std::vector<std::string>& directories,
                                  SkipDir skips = SkipDir::None,
                                  Case input_case = Case::kUpperCamel) const {
    const bool skip_output_path =
        (skips & SkipDir::OutputPath) != SkipDir::None;
    const bool skip_trailing_seperator =
        (skips & SkipDir::TrailingPathSeperator) != SkipDir::None;
    std::string result = skip_output_path ? "" : config_.output_path;
    for (auto d = directories.begin(); d != directories.end(); d++) {
      result += ConvertCase(*d, config_.directories, input_case);
      result.push_back(kPathSeparator);
    }
    if (skip_trailing_seperator && !result.empty()) result.pop_back();
    return result;
  }

  virtual std::string EscapeKeyword(const std::string& name) const {
    std::string cased_name(name);

    if (config_.keywords_casing == Config::KeywordsCasing::CaseInsensitive) {
      for (auto chr = cased_name.begin(); chr != cased_name.end(); chr++) {
        *chr = CharToLower(*chr);
      }
    }
    if (keywords_.find(cased_name) == keywords_.end()) {
      return name;
    } else {
      return config_.keyword_prefix + name + config_.keyword_suffix;
    }
  }

  virtual std::string Type(const std::string& s) const {
    return Format(s, config_.types);
  }
  virtual std::string Type(const std::string& t, const std::string& s) const {
    return Format(t + "_" + s, config_.types);
  }

  virtual std::string ObjectType(const std::string& s) const {
    return config_.object_prefix + Type(s) + config_.object_suffix;
  }

  virtual std::string Field(const std::string& s) const {

Review comment (suggestion):
can you put into a method?

Also, prefer to use an existing function: https://github.com/google/flatbuffers/blob/master/src/util.cpp#L130

Code after:

  // Formats `directories` prefixed with the output_path and joined with the
  // right seperator. Output path prefixing and the trailing separator may be
  // skiped using `skips`.
  // Callers may want to use `EnsureDirExists` with the result.
  // input_case is used to tell how to modify namespace. e.g. kUpperCamel will
  // add a underscode between case changes, so MyGame turns into My_Game
  // (depending also on the output_case).
  virtual std::string Directories(const std::vector<std::string>& directories,
                                  SkipDir skips = SkipDir::None,
                                  Case input_case = Case::kUpperCamel) const {
    const bool skip_output_path =
        (skips & SkipDir::OutputPath) != SkipDir::None;
    const bool skip_trailing_seperator =
        (skips & SkipDir::TrailingPathSeperator) != SkipDir::None;
    std::string result = skip_output_path ? "" : config_.output_path;
    for (auto d = directories.begin(); d != directories.end(); d++) {
      result += ConvertCase(*d, config_.directories, input_case);
      result.push_back(kPathSeparator);
    }
    if (skip_trailing_seperator && !result.empty()) result.pop_back();
    return result;
  }

  virtual std::string NormalizeKeywordCase(const std::string& name) const {
    if (config_.keywords_casing == Config::KeywordsCasing::CaseInsensitive) {
      return ConvertCase(name, Case::kAllLower);
    } else {
      return name;
    }
  }

  virtual std::string EscapeKeyword(const std::string& name) const {
    if (keywords_.find(NormalizeKeywordCase(name)) == keywords_.end()) {
      return name;
    } else {
      return config_.keyword_prefix + name + config_.keyword_suffix;
    }
  }

  virtual std::string Type(const std::string& s) const {
    return Format(s, config_.types);
  }
  virtual std::string Type(const std::string& t, const std::string& s) const {
    return Format(t + "_" + s, config_.types);
  }

  virtual std::string ObjectType(const std::string& s) const {
    return config_.object_prefix + Type(s) + config_.object_suffix;
  }