<commit_before>// Protocol Buffers for Objective C
//
// Copyright 2010 Booyah Inc.
// Copyright 2008 Google Inc.
//
// 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.

#include "objc_helpers.h"

#include <vector>

#include <google/protobuf/stubs/hash.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/stubs/strutil.h>

#include "google/protobuf/objectivec-descriptor.pb.h"

namespace google { namespace protobuf { namespace compiler { namespace objectivec {
  namespace {
    const string& FieldName(const FieldDescriptor* field) {
      // Groups are hacky:  The name of the field is just the lower-cased name
      // of the group type.  In ObjectiveC, though, we would like to retain the original
      // capitalization of the type name.
      if (field->type() == FieldDescriptor::TYPE_GROUP) {
        return field->message_type()->name();
      } else {
        return field->name();
      }
    }
  }


    string UnderscoresToCapitalizedCamelCase(const string& input) {
      vector<string> values;
      string current;

      bool last_char_was_number = false;
      bool last_char_was_lower = false;
      bool last_char_was_upper = false;
      for (int i = 0; i < input.size(); i++) {
        char c = input[i];
        if (c >= '0' && c <= '9') {
          if (!last_char_was_number) {
            values.push_back(current);
            current = "";
          }
          current += c;
          last_char_was_number = last_char_was_lower = last_char_was_upper = false;
          last_char_was_number = true;
        } else if (c >= 'a' && c <= 'z') {
          // lowercase letter can follow a lowercase or uppercase letter
          if (!last_char_was_lower && !last_char_was_upper) {
            values.push_back(current);
            current = "";
          }
          current += c;
          last_char_was_number = last_char_was_lower = last_char_was_upper = false;
          last_char_was_lower = true;
        } else if (c >= 'A' && c <= 'Z') {
          if (!last_char_was_upper) {
            values.push_back(current);
            current = "";
          }
          current += c;
          last_char_was_number = last_char_was_lower = last_char_was_upper = false;
          last_char_was_upper = true;
        } else {
          last_char_was_number = last_char_was_lower = last_char_was_upper = false;
        }
      }
      values.push_back(current);

      for (vector<string>::iterator i = values.begin(); i != values.end(); ++i) {
        string value = *i;
        for (int j = 0; j < value.length(); j++) {
          if (j == 0) {
            value[j] = toupper(value[j]);
          } else {
            value[j] = tolower(value[j]);
          }
        }
        *i = value;
      }
      string result;
      for (vector<string>::iterator i = values.begin(); i != values.end(); ++i) {
        result += *i;
      }
      return result;
    }


    string UnderscoresToCamelCase(const string& input) {
      string result = UnderscoresToCapitalizedCamelCase(input);
      if (result.length() == 0) {
        return result;
      }

      result[0] = tolower(result[0]);
      return result;
    }


  string UnderscoresToCamelCase(const FieldDescriptor* field) {
    return UnderscoresToCamelCase(FieldName(field));
  }


  string UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field) {
    return UnderscoresToCapitalizedCamelCase(FieldName(field));
  }


  string UnderscoresToCamelCase(const MethodDescriptor* method) {
    return UnderscoresToCamelCase(method->name());
  }


  string FilenameToCamelCase(const string& filename) {
    string result;
    bool need_uppercase = true;

    result.reserve(filename.length());

    for (string::const_iterator it(filename.begin()), itEnd(filename.end()); it != itEnd; ++it) {
      const char c = *it;

      // Ignore non-alphanumeric characters.  The next alphanumeric character
      // must be uppercased, though.
      if (!isalnum(c)) {
        need_uppercase = true;
        continue;
      }

      // If an uppercased character has been requested, transform the current
      // character, append it to the result, reset the flag, and move on.
      // This is safe to do even if the character is already uppercased.<commit_msg>Allow '_' (underscores) in filenames.<commit_after>// Protocol Buffers for Objective C
//
// Copyright 2010 Booyah Inc.
// Copyright 2008 Google Inc.
//
// 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.

#include "objc_helpers.h"

#include <vector>

#include <google/protobuf/stubs/hash.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/stubs/strutil.h>

#include "google/protobuf/objectivec-descriptor.pb.h"

namespace google { namespace protobuf { namespace compiler { namespace objectivec {
  namespace {
    const string& FieldName(const FieldDescriptor* field) {
      // Groups are hacky:  The name of the field is just the lower-cased name
      // of the group type.  In ObjectiveC, though, we would like to retain the original
      // capitalization of the type name.
      if (field->type() == FieldDescriptor::TYPE_GROUP) {
        return field->message_type()->name();
      } else {
        return field->name();
      }
    }
  }


    string UnderscoresToCapitalizedCamelCase(const string& input) {
      vector<string> values;
      string current;

      bool last_char_was_number = false;
      bool last_char_was_lower = false;
      bool last_char_was_upper = false;
      for (int i = 0; i < input.size(); i++) {
        char c = input[i];
        if (c >= '0' && c <= '9') {
          if (!last_char_was_number) {
            values.push_back(current);
            current = "";
          }
          current += c;
          last_char_was_number = last_char_was_lower = last_char_was_upper = false;
          last_char_was_number = true;
        } else if (c >= 'a' && c <= 'z') {
          // lowercase letter can follow a lowercase or uppercase letter
          if (!last_char_was_lower && !last_char_was_upper) {
            values.push_back(current);
            current = "";
          }
          current += c;
          last_char_was_number = last_char_was_lower = last_char_was_upper = false;
          last_char_was_lower = true;
        } else if (c >= 'A' && c <= 'Z') {
          if (!last_char_was_upper) {
            values.push_back(current);
            current = "";
          }
          current += c;
          last_char_was_number = last_char_was_lower = last_char_was_upper = false;
          last_char_was_upper = true;
        } else {
          last_char_was_number = last_char_was_lower = last_char_was_upper = false;
        }
      }
      values.push_back(current);

      for (vector<string>::iterator i = values.begin(); i != values.end(); ++i) {
        string value = *i;
        for (int j = 0; j < value.length(); j++) {
          if (j == 0) {
            value[j] = toupper(value[j]);
          } else {
            value[j] = tolower(value[j]);
          }
        }
        *i = value;
      }
      string result;
      for (vector<string>::iterator i = values.begin(); i != values.end(); ++i) {
        result += *i;
      }
      return result;
    }


    string UnderscoresToCamelCase(const string& input) {
      string result = UnderscoresToCapitalizedCamelCase(input);
      if (result.length() == 0) {
        return result;
      }

      result[0] = tolower(result[0]);
      return result;
    }


  string UnderscoresToCamelCase(const FieldDescriptor* field) {
    return UnderscoresToCamelCase(FieldName(field));
  }


  string UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field) {
    return UnderscoresToCapitalizedCamelCase(FieldName(field));
  }


  string UnderscoresToCamelCase(const MethodDescriptor* method) {
    return UnderscoresToCamelCase(method->name());
  }


  string FilenameToCamelCase(const string& filename) {
    string result;
    bool need_uppercase = true;

    result.reserve(filename.length());

    for (string::const_iterator it(filename.begin()), itEnd(filename.end()); it != itEnd; ++it) {
      const char c = *it;

      // Ignore undesirable characters.  The good character must be
      // uppercased, though.
      if (!isalnum(c) && c != '_') {
        need_uppercase = true;
        continue;
      }

      // If an uppercased character has been requested, transform the current
      // character, append it to the result, reset the flag, and move on.
      // This is safe to do even if the character is already uppercased.
{'fraction_non_alphanumeric': 0.11090146750524109, 'fraction_numerical': 0.0041928721174004195, 'mean_word_length': 2.4719796215429404, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6173919', 'n_tokens_mistral': 2868, 'n_tokens_neox': 2777, 'n_words': 800}