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

Add padStart/padEnd methods. Refactor string copy, compare and repeat #171

Merged
merged 30 commits into from
Jul 25, 2018
Merged

Add padStart/padEnd methods. Refactor string copy, compare and repeat #171

merged 30 commits into from
Jul 25, 2018

Conversation

MaxGraey
Copy link
Member

No description provided.

var padLen = padString.length;
if (targetLength < length || !padLen) return this;
var len = targetLength - length;
if (len > padLen) padString = padString.repeat(len / padLen + 1);
Copy link
Member

Choose a reason for hiding this comment

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

if len = 4, padLen = 2, this would repeat the string 4 / 2 + 1 = 3 times (I'd expect 2 times) - is that correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. I can improve this for case, when reminder is zero after division

memory.copy(
changetype<usize>(out) + HEADER_SIZE + (<usize>length << 1),
changetype<usize>(padString) + HEADER_SIZE,
<usize>targetLength << 1
Copy link
Member

Choose a reason for hiding this comment

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

Does this copy out of bounds? Rather <usize>len << 1 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed!

changetype<usize>(out),
changetype<usize>(padString),
padLen,
(len + padLen - 1) / padLen
Copy link
Member Author

Choose a reason for hiding this comment

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

Need replace to len/padLen + rest copy

destOffset: usize,
src: String,
length: i32,
count: i32
Copy link
Member

Choose a reason for hiding this comment

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

What are length and count? Can't one be computed from the other?

Copy link
Member Author

@MaxGraey MaxGraey Jul 24, 2018

Choose a reason for hiding this comment

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

length is length of repeated source. Is better rename it to srcLenght?
EDIT. Yep can remove length after refactoring. Not needed anymore

Copy link
Member Author

Choose a reason for hiding this comment

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

count is how many repeat times we want

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@MaxGraey MaxGraey changed the title Add String#padStart and String#padEnd methods Add padStart/padEnd methods. Refactor string copy and repeat Jul 25, 2018
@MaxGraey MaxGraey changed the title Add padStart/padEnd methods. Refactor string copy and repeat Add padStart/padEnd methods. Refactor string copy, compare and repeat Jul 25, 2018
@dcodeIO dcodeIO merged commit 671121b into AssemblyScript:master Jul 25, 2018
@dcodeIO
Copy link
Member

dcodeIO commented Jul 25, 2018

Thank you! :)

@MaxGraey MaxGraey deleted the add-more-string-methods branch July 25, 2018 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants