Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdd236bf

Browse files
Don't mess with the original in String::substring
Before, substring would (temporarily) add a \0 in the original string atthe end of the substring, so the substring could be copied into a newString object. However, now that the String::copy() method can work withnon-nul-terminated strings (by passing an explicit length), this trickis not needed and we can just call the copy method instead.
1 parent8431488 commitdd236bf

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

‎api/String.cpp‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,7 @@ String String::substring(unsigned int left, unsigned int right) const
632632
String out;
633633
if (left >= len)return out;
634634
if (right > len) right = len;
635-
char temp = buffer[right];// save the replaced character
636-
buffer[right] ='\0';
637-
out = buffer + left;// pointer arithmetic
638-
buffer[right] = temp;//restore character
635+
out.copy(buffer + left, right - left);
639636
return out;
640637
}
641638

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp