File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 27
27
#include " platform/CCCommon.h"
28
28
#include " base/CCConsole.h"
29
29
#include " ConvertUTF.h"
30
+ #include < limits>
30
31
31
32
NS_CC_BEGIN
32
33
@@ -379,12 +380,28 @@ void StringUTF8::replace(const std::string& newStr)
379
380
}
380
381
381
382
std::string StringUTF8::getAsCharSequence () const
383
+ {
384
+ return getAsCharSequence (0 , std::numeric_limits<std::size_t >::max ());
385
+ }
386
+
387
+ std::string StringUTF8::getAsCharSequence (std::size_t pos) const
388
+ {
389
+ return getAsCharSequence (pos, std::numeric_limits<std::size_t >::max ());
390
+ }
391
+
392
+ std::string StringUTF8::getAsCharSequence (std::size_t pos, std::size_t len) const
382
393
{
383
394
std::string charSequence;
395
+ std::size_t maxLen = _str.size () - pos;
396
+ if (len > maxLen)
397
+ {
398
+ len = maxLen;
399
+ }
384
400
385
- for (auto & charUtf8 : _str)
401
+ std::size_t endPos = len + pos;
402
+ while (pos < endPos)
386
403
{
387
- charSequence.append (charUtf8 ._char );
404
+ charSequence.append (_str[pos++] ._char );
388
405
}
389
406
390
407
return charSequence;
Original file line number Diff line number Diff line change @@ -196,7 +196,7 @@ class CC_DLL StringUTF8
196
196
struct CharUTF8
197
197
{
198
198
std::string _char;
199
- bool isAnsi () { return _char.size () == 1 ; }
199
+ bool isASCII () const { return _char.size () == 1 ; }
200
200
};
201
201
typedef std::vector<CharUTF8> CharUTF8Store;
202
202
@@ -208,12 +208,15 @@ class CC_DLL StringUTF8
208
208
void replace (const std::string& newStr);
209
209
210
210
std::string getAsCharSequence () const ;
211
+ std::string getAsCharSequence (std::size_t pos) const ;
212
+ std::string getAsCharSequence (std::size_t pos, std::size_t len) const ;
211
213
212
214
bool deleteChar (std::size_t pos);
213
215
bool insert (std::size_t pos, const std::string& insertStr);
214
216
bool insert (std::size_t pos, const StringUTF8& insertStr);
215
217
216
218
CharUTF8Store& getString () { return _str; }
219
+ const CharUTF8Store& getString () const { return _str; }
217
220
218
221
private:
219
222
CharUTF8Store _str;
You can’t perform that action at this time.
0 commit comments