-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement String.prototype.trim() #191
Conversation
|
||
new_len = len - prefix - postfix; | ||
|
||
MEM_DEFINE_LOCAL_ARRAY (new_str_buffer, new_len+1, ecma_char_t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new_len + 1
@@ -554,7 +555,62 @@ ecma_builtin_string_prototype_object_to_locale_upper_case (ecma_value_t this_arg | |||
static ecma_completion_value_t | |||
ecma_builtin_string_prototype_object_trim (ecma_value_t this_arg) /**< this argument */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests for trim
, please.
Like from here:
var orig = ' foo ';
console.log(orig.trim());
var orig = 'foo ';
console.log(orig.trim()); // 'foo'
fa5b9a5
to
722faf8
Compare
Thanks for the review, the patch is updated and tests are added. |
@@ -14,6 +14,7 @@ | |||
* limitations under the License. | |||
*/ | |||
|
|||
#include <ctype.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK: we usually use the jrt-libc-include.h and not directly the ctype.h/other libc headers.
eddb47c
to
c4c0437
Compare
ecma_op_to_string (this_arg), | ||
ret_value); | ||
|
||
if (ecma_is_completion_value_empty (ret_value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this check as inside the ECMA_TRY_CATCH the ret_value is an empty value.
JerryScript-DCO-1.0-Signed-off-by: Laszlo Vidacs [email protected]
c4c0437
to
2c93ffd
Compare
prefix++; | ||
} | ||
|
||
while (postfix < len - prefix && isspace (original_zt_str_p[len-postfix-1])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
len - postfix - 1
Good to me after fixing. |
JerryScript-DCO-1.0-Signed-off-by: Laszlo Vidacs [email protected]
2c93ffd
to
58f49ca
Compare
Thanks for the reviews, the patch is updated. |
if @galpeter is OK, |
looks better, lgtm |
Rebased & squased & merged: caa1617 |
JerryScript-DCO-1.0-Signed-off-by: Laszlo Vidacs [email protected]