|
|
|
@ -1101,116 +1101,6 @@ bool ValidateObjCClassPrefixes(const std::vector<const FileDescriptor*>& files, |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
// Helper to build up the decode data for a string.
|
|
|
|
|
class DecodeDataBuilder { |
|
|
|
|
public: |
|
|
|
|
DecodeDataBuilder() { Reset(); } |
|
|
|
|
|
|
|
|
|
bool AddCharacter(const char desired, const char input); |
|
|
|
|
void AddUnderscore() { |
|
|
|
|
Push(); |
|
|
|
|
need_underscore_ = true; |
|
|
|
|
} |
|
|
|
|
std::string Finish() { |
|
|
|
|
Push(); |
|
|
|
|
return decode_data_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
static constexpr uint8_t kAddUnderscore = 0x80; |
|
|
|
|
|
|
|
|
|
static constexpr uint8_t kOpAsIs = 0x00; |
|
|
|
|
static constexpr uint8_t kOpFirstUpper = 0x40; |
|
|
|
|
static constexpr uint8_t kOpFirstLower = 0x20; |
|
|
|
|
static constexpr uint8_t kOpAllUpper = 0x60; |
|
|
|
|
|
|
|
|
|
static constexpr int kMaxSegmentLen = 0x1f; |
|
|
|
|
|
|
|
|
|
void AddChar(const char desired) { |
|
|
|
|
++segment_len_; |
|
|
|
|
is_all_upper_ &= absl::ascii_isupper(desired); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Push() { |
|
|
|
|
uint8_t op = (op_ | segment_len_); |
|
|
|
|
if (need_underscore_) op |= kAddUnderscore; |
|
|
|
|
if (op != 0) { |
|
|
|
|
decode_data_ += (char)op; |
|
|
|
|
} |
|
|
|
|
Reset(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool AddFirst(const char desired, const char input) { |
|
|
|
|
if (desired == input) { |
|
|
|
|
op_ = kOpAsIs; |
|
|
|
|
} else if (desired == absl::ascii_toupper(input)) { |
|
|
|
|
op_ = kOpFirstUpper; |
|
|
|
|
} else if (desired == absl::ascii_tolower(input)) { |
|
|
|
|
op_ = kOpFirstLower; |
|
|
|
|
} else { |
|
|
|
|
// Can't be transformed to match.
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
AddChar(desired); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Reset() { |
|
|
|
|
need_underscore_ = false; |
|
|
|
|
op_ = 0; |
|
|
|
|
segment_len_ = 0; |
|
|
|
|
is_all_upper_ = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool need_underscore_; |
|
|
|
|
bool is_all_upper_; |
|
|
|
|
uint8_t op_; |
|
|
|
|
int segment_len_; |
|
|
|
|
|
|
|
|
|
std::string decode_data_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
bool DecodeDataBuilder::AddCharacter(const char desired, const char input) { |
|
|
|
|
// If we've hit the max size, push to start a new segment.
|
|
|
|
|
if (segment_len_ == kMaxSegmentLen) { |
|
|
|
|
Push(); |
|
|
|
|
} |
|
|
|
|
if (segment_len_ == 0) { |
|
|
|
|
return AddFirst(desired, input); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Desired and input match...
|
|
|
|
|
if (desired == input) { |
|
|
|
|
// If we aren't transforming it, or we're upper casing it and it is
|
|
|
|
|
// supposed to be uppercase; just add it to the segment.
|
|
|
|
|
if ((op_ != kOpAllUpper) || absl::ascii_isupper(desired)) { |
|
|
|
|
AddChar(desired); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Add the current segment, and start the next one.
|
|
|
|
|
Push(); |
|
|
|
|
return AddFirst(desired, input); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// If we need to uppercase, and everything so far has been uppercase,
|
|
|
|
|
// promote op to AllUpper.
|
|
|
|
|
if ((desired == absl::ascii_toupper(input)) && is_all_upper_) { |
|
|
|
|
op_ = kOpAllUpper; |
|
|
|
|
AddChar(desired); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Give up, push and start a new segment.
|
|
|
|
|
Push(); |
|
|
|
|
return AddFirst(desired, input); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
} // namespace objectivec
|
|
|
|
|
} // namespace compiler
|
|
|
|
|
} // namespace protobuf
|
|
|
|
|