diff options
| author | Nathan Warden | 2015-02-19 19:35:04 -0500 |
|---|---|---|
| committer | Nathan Warden | 2015-02-19 19:35:04 -0500 |
| commit | 8f5bf2a2ef96ea2d189d09a8cdd8d0a15deceb00 (patch) | |
| tree | 52e43b18514b40ff1bc8230855ef19b7da490cb0 /core/ustring.cpp | |
| parent | 31e076d16affca682e956c966c0a8f9218a2b192 (diff) | |
| download | godot-8f5bf2a2ef96ea2d189d09a8cdd8d0a15deceb00.tar.gz godot-8f5bf2a2ef96ea2d189d09a8cdd8d0a15deceb00.tar.zst godot-8f5bf2a2ef96ea2d189d09a8cdd8d0a15deceb00.zip | |
Diffstat (limited to 'core/ustring.cpp')
| -rw-r--r-- | core/ustring.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp index 476ab3f93..8ad1d434d 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -482,7 +482,7 @@ void String::erase(int p_pos, int p_chars) { String String::capitalize() const { - String aux=this->replace("_"," ").to_lower(); + String aux=this->camelcase_to_underscore().replace("_"," ").to_lower(); String cap; for (int i=0;i<aux.get_slice_count(" ");i++) { @@ -498,6 +498,29 @@ String String::capitalize() const { return cap; } + + +String String::camelcase_to_underscore() const { + const CharType * cstr = c_str(); + String newString; + const char A = 'A', Z = 'Z'; + int startIndex = 0; + + for ( int i = 1; i < this->size()-1; i++ ) { + bool isCapital = cstr[i] >= A && cstr[i] <= Z; + + if ( isCapital ) { + newString += "_" + this->substr(startIndex, i-startIndex); + startIndex = i; + } + } + + newString += "_" + this->substr(startIndex, this->size()-startIndex); + + return newString; +} + + int String::get_slice_count(String p_splitter) const{ if (empty()) |
