From 8f5bf2a2ef96ea2d189d09a8cdd8d0a15deceb00 Mon Sep 17 00:00:00 2001 From: Nathan Warden Date: Thu, 19 Feb 2015 19:35:04 -0500 Subject: [PATCH] Camelcased script variables will now capitalize in the inspector. --- core/ustring.cpp | 25 ++++++++++++++++++++++++- core/ustring.h | 3 +-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/ustring.cpp b/core/ustring.cpp index 476ab3f9366..8ad1d434d4b 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;isize()-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()) diff --git a/core/ustring.h b/core/ustring.h index af5ffb7c359..c7da26a695c 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -149,6 +149,7 @@ public: static double to_double(const CharType* p_str, const CharType **r_end=NULL); static int64_t to_int(const CharType* p_str,int p_len=-1); String capitalize() const; + String camelcase_to_underscore() const; int get_slice_count(String p_splitter) const; String get_slice(String p_splitter,int p_slice) const; @@ -225,8 +226,6 @@ public: String(const char *p_str); String(const CharType *p_str,int p_clip_to_len=-1); String(const StrRange& p_range); - - };