File tree Expand file tree Collapse file tree 1 file changed +6
-23
lines changed
inst/include/Rcpp/sugar/functions/strings Expand file tree Collapse file tree 1 file changed +6
-23
lines changed Original file line number Diff line number Diff line change @@ -38,22 +38,15 @@ inline bool isws(const char c) {
3838}
3939
4040inline const char * trim_left (const char * str) {
41- static std::string buff;
42-
4341 if (!str) {
4442 return " " ;
4543 }
4644
47- buff.clear ();
48- char c = *str;
49-
50- while (isws (c)) {
45+ while (isws (*str)) {
5146 ++str;
52- c = *str;
5347 }
5448
55- buff.append (str);
56- return buff.c_str ();
49+ return str;
5750}
5851
5952inline const char * trim_right (const char * str) {
@@ -67,11 +60,8 @@ inline const char* trim_right(const char* str) {
6760 std::size_t sz = std::strlen (str);
6861
6962 const char * ptr = str + sz - 1 ;
70- char c = *ptr;
7163
72- for (; ptr > str && isws (c); c = *ptr) {
73- --sz; --ptr;
74- }
64+ for (; ptr > str && isws (*ptr); --sz, --ptr);
7565
7666 buff.append (str, sz - isws (*ptr));
7767 return buff.c_str ();
@@ -85,24 +75,17 @@ inline const char* trim_both(const char* str) {
8575 }
8676
8777 buff.clear ();
88- char c = *str;
8978
90- while (isws (c )) {
79+ while (isws (*str )) {
9180 ++str;
92- c = *str;
9381 }
9482
9583 std::size_t sz = std::strlen (str);
9684 const char * ptr = str + sz - 1 ;
97- c = *ptr;
9885
99- for (; ptr >= str; c = *ptr, --sz, --ptr) {
100- if (!isws (c)) {
101- break ;
102- }
103- }
86+ for (; ptr > str && isws (*ptr); --sz, --ptr);
10487
105- buff.append (str, sz + 1 );
88+ buff.append (str, sz);
10689 return buff.c_str ();
10790}
10891
You can’t perform that action at this time.
0 commit comments