Some more camelCase string utilities.

Swift SVN r16053
This commit is contained in:
Doug Gregor
2014-04-08 15:13:18 +00:00
parent 015c2743c4
commit 5d20720e87
2 changed files with 44 additions and 0 deletions

View File

@@ -115,6 +115,16 @@ bool camel_case::sameWordIgnoreFirstCase(StringRef word1, StringRef word2) {
return word1.substr(1) == word2.substr(1);
}
bool camel_case::startsWithIgnoreFirstCase(StringRef word1, StringRef word2) {
if (word1.size() < word2.size())
return false;
if (clang::toLowercase(word1[0]) != clang::toLowercase(word2[0]))
return false;
return word1.substr(1) == word2.substr(1, word1.size() - 1);
}
StringRef camel_case::toLowercaseWord(StringRef string,
SmallVectorImpl<char> &scratch) {
if (string.empty())
@@ -151,6 +161,27 @@ StringRef camel_case::toSentencecase(StringRef string,
return StringRef(scratch.data(), scratch.size());
}
StringRef camel_case::dropPrefix(StringRef string) {
unsigned firstLower = 0, n = string.size();
if (n < 4)
return string;
for (; firstLower < n; ++firstLower) {
if (!clang::isUppercase(string[firstLower]))
break;
}
if (firstLower == n)
return string;
if (firstLower >= 3 && firstLower <= 4)
return string.substr(firstLower - 1);
return string;
}
Words::reverse_iterator MultiWordMap::match(Words::reverse_iterator first,
Words::reverse_iterator last) const{
assert(first != last && "Empty sequence cannot be matched");