|
@@ -88,7 +88,6 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
|
|
|
std::string LabelForField(FieldDescriptor* field);
|
|
|
std::string TypeName(FieldDescriptor* field);
|
|
|
std::string UnderscoresToCamelCase(const string& name, bool cap_first_letter);
|
|
|
-std::string EscapeDollor(const string& to_escape);
|
|
|
std::string BinaryToHex(const string& binary);
|
|
|
void Indent(io::Printer* printer);
|
|
|
void Outdent(io::Printer* printer);
|
|
@@ -153,7 +152,7 @@ template <typename DescriptorType>
|
|
|
std::string ClassNamePrefix(const string& classname,
|
|
|
const DescriptorType* desc) {
|
|
|
const string& prefix = (desc->file()->options()).php_class_prefix();
|
|
|
- if (prefix != "") {
|
|
|
+ if (!prefix.empty()) {
|
|
|
return prefix;
|
|
|
}
|
|
|
|
|
@@ -244,13 +243,13 @@ template <typename DescriptorType>
|
|
|
std::string RootPhpNamespace(const DescriptorType* desc, bool is_descriptor) {
|
|
|
if (desc->file()->options().has_php_namespace()) {
|
|
|
const string& php_namespace = desc->file()->options().php_namespace();
|
|
|
- if (php_namespace != "") {
|
|
|
+ if (!php_namespace.empty()) {
|
|
|
return php_namespace;
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
- if (desc->file()->package() != "") {
|
|
|
+ if (!desc->file()->package().empty()) {
|
|
|
return PhpName(desc->file()->package(), is_descriptor);
|
|
|
}
|
|
|
return "";
|
|
@@ -260,7 +259,7 @@ template <typename DescriptorType>
|
|
|
std::string FullClassName(const DescriptorType* desc, bool is_descriptor) {
|
|
|
string classname = GeneratedClassNameImpl(desc);
|
|
|
string php_namespace = RootPhpNamespace(desc, is_descriptor);
|
|
|
- if (php_namespace != "") {
|
|
|
+ if (!php_namespace.empty()) {
|
|
|
return php_namespace + "\\" + classname;
|
|
|
}
|
|
|
return classname;
|
|
@@ -270,7 +269,7 @@ template <typename DescriptorType>
|
|
|
std::string LegacyFullClassName(const DescriptorType* desc, bool is_descriptor) {
|
|
|
string classname = LegacyGeneratedClassName(desc);
|
|
|
string php_namespace = RootPhpNamespace(desc, is_descriptor);
|
|
|
- if (php_namespace != "") {
|
|
|
+ if (!php_namespace.empty()) {
|
|
|
return php_namespace + "\\" + classname;
|
|
|
}
|
|
|
return classname;
|
|
@@ -352,7 +351,7 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file,
|
|
|
if (file->options().has_php_metadata_namespace()) {
|
|
|
const string& php_metadata_namespace =
|
|
|
file->options().php_metadata_namespace();
|
|
|
- if (php_metadata_namespace != "" && php_metadata_namespace != "\\") {
|
|
|
+ if (!php_metadata_namespace.empty() && php_metadata_namespace != "\\") {
|
|
|
result += php_metadata_namespace;
|
|
|
std::replace(result.begin(), result.end(), '\\', '/');
|
|
|
if (result.at(result.size() - 1) != '/') {
|
|
@@ -552,45 +551,41 @@ std::string EnumOrMessageSuffix(
|
|
|
|
|
|
// Converts a name to camel-case. If cap_first_letter is true, capitalize the
|
|
|
// first letter.
|
|
|
-std::string UnderscoresToCamelCase(const string& input, bool cap_first_letter) {
|
|
|
+std::string UnderscoresToCamelCase(const string& name, bool cap_first_letter) {
|
|
|
std::string result;
|
|
|
- for (int i = 0; i < input.size(); i++) {
|
|
|
- if ('a' <= input[i] && input[i] <= 'z') {
|
|
|
+ for (int i = 0; i < name.size(); i++) {
|
|
|
+ if ('a' <= name[i] && name[i] <= 'z') {
|
|
|
if (cap_first_letter) {
|
|
|
- result += input[i] + ('A' - 'a');
|
|
|
+ result += name[i] + ('A' - 'a');
|
|
|
} else {
|
|
|
- result += input[i];
|
|
|
+ result += name[i];
|
|
|
}
|
|
|
cap_first_letter = false;
|
|
|
- } else if ('A' <= input[i] && input[i] <= 'Z') {
|
|
|
+ } else if ('A' <= name[i] && name[i] <= 'Z') {
|
|
|
if (i == 0 && !cap_first_letter) {
|
|
|
// Force first letter to lower-case unless explicitly told to
|
|
|
// capitalize it.
|
|
|
- result += input[i] + ('a' - 'A');
|
|
|
+ result += name[i] + ('a' - 'A');
|
|
|
} else {
|
|
|
// Capital letters after the first are left as-is.
|
|
|
- result += input[i];
|
|
|
+ result += name[i];
|
|
|
}
|
|
|
cap_first_letter = false;
|
|
|
- } else if ('0' <= input[i] && input[i] <= '9') {
|
|
|
- result += input[i];
|
|
|
+ } else if ('0' <= name[i] && name[i] <= '9') {
|
|
|
+ result += name[i];
|
|
|
cap_first_letter = true;
|
|
|
} else {
|
|
|
cap_first_letter = true;
|
|
|
}
|
|
|
}
|
|
|
// Add a trailing "_" if the name should be altered.
|
|
|
- if (input[input.size() - 1] == '#') {
|
|
|
+ if (name[name.size() - 1] == '#') {
|
|
|
result += '_';
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-std::string EscapeDollor(const string& to_escape) {
|
|
|
- return StringReplace(to_escape, "$", "\\$", true);
|
|
|
-}
|
|
|
-
|
|
|
-std::string BinaryToHex(const string& src) {
|
|
|
+std::string BinaryToHex(const string& binary) {
|
|
|
string dest;
|
|
|
size_t i;
|
|
|
unsigned char symbol[16] = {
|
|
@@ -600,12 +595,12 @@ std::string BinaryToHex(const string& src) {
|
|
|
'c', 'd', 'e', 'f',
|
|
|
};
|
|
|
|
|
|
- dest.resize(src.size() * 2);
|
|
|
+ dest.resize(binary.size() * 2);
|
|
|
char* append_ptr = &dest[0];
|
|
|
|
|
|
- for (i = 0; i < src.size(); i++) {
|
|
|
- *append_ptr++ = symbol[(src[i] & 0xf0) >> 4];
|
|
|
- *append_ptr++ = symbol[src[i] & 0x0f];
|
|
|
+ for (i = 0; i < binary.size(); i++) {
|
|
|
+ *append_ptr++ = symbol[(binary[i] & 0xf0) >> 4];
|
|
|
+ *append_ptr++ = symbol[binary[i] & 0x0f];
|
|
|
}
|
|
|
|
|
|
return dest;
|
|
@@ -1103,7 +1098,7 @@ void LegacyGenerateClassFile(const FileDescriptor* file, const DescriptorType* d
|
|
|
GenerateHead(file, &printer);
|
|
|
|
|
|
std::string php_namespace = RootPhpNamespace(desc, is_descriptor);
|
|
|
- if (php_namespace != "") {
|
|
|
+ if (!php_namespace.empty()) {
|
|
|
printer.Print(
|
|
|
"namespace ^name^;\n\n",
|
|
|
"name", php_namespace);
|