Skip to content
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

Closed

Conversation

lvidacs
Copy link
Contributor

@lvidacs lvidacs commented Jun 15, 2015

JerryScript-DCO-1.0-Signed-off-by: Laszlo Vidacs [email protected]

@egavrin egavrin added this to the ECMA builtins milestone Jun 15, 2015
@egavrin egavrin added ecma builtins Related to ECMA built-in routines development Feature implementation labels Jun 15, 2015

new_len = len - prefix - postfix;

MEM_DEFINE_LOCAL_ARRAY (new_str_buffer, new_len+1, ecma_char_t);
Copy link
Contributor

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 */
Copy link
Contributor

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'

@lvidacs lvidacs force-pushed the string_prototype_trim branch from fa5b9a5 to 722faf8 Compare June 16, 2015 08:28
@lvidacs
Copy link
Contributor Author

lvidacs commented Jun 16, 2015

Thanks for the review, the patch is updated and tests are added.

@ILyoan ILyoan mentioned this pull request Jun 17, 2015
25 tasks
@galpeter galpeter mentioned this pull request Jun 17, 2015
29 tasks
@@ -14,6 +14,7 @@
* limitations under the License.
*/

#include <ctype.h>
Copy link
Contributor

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.

@lvidacs lvidacs force-pushed the string_prototype_trim branch from eddb47c to c4c0437 Compare June 22, 2015 14:27
ecma_op_to_string (this_arg),
ret_value);

if (ecma_is_completion_value_empty (ret_value))
Copy link
Contributor

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]
@lvidacs lvidacs force-pushed the string_prototype_trim branch from c4c0437 to 2c93ffd Compare June 23, 2015 10:07
prefix++;
}

while (postfix < len - prefix && isspace (original_zt_str_p[len-postfix-1]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len - postfix - 1

@egavrin
Copy link
Contributor

egavrin commented Jun 23, 2015

Good to me after fixing.

JerryScript-DCO-1.0-Signed-off-by: Laszlo Vidacs [email protected]
@lvidacs lvidacs force-pushed the string_prototype_trim branch from 2c93ffd to 58f49ca Compare June 23, 2015 10:39
@lvidacs
Copy link
Contributor Author

lvidacs commented Jun 23, 2015

Thanks for the reviews, the patch is updated.

@egavrin
Copy link
Contributor

egavrin commented Jun 23, 2015

if @galpeter is OK, make push

@galpeter
Copy link
Contributor

looks better, lgtm

@galpeter
Copy link
Contributor

Rebased & squased & merged: caa1617

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Feature implementation ecma builtins Related to ECMA built-in routines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants