-
-
Notifications
You must be signed in to change notification settings - Fork 185
Fix some string operations #895
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cbc49bb
Fix string.slice, string.substring, string.substr
ark120202 23ff416
Fix string.charAt and string.charCodeAt
ark120202 ed9b8ff
Fix string.indexOf with negative indexes
ark120202 6707c04
Fix out-of-bounds string access being "" instead of undefined
ark120202 7842e58
Fix array.join flacky test
ark120202 8ad270f
Feedback
ark120202 cf58056
Replace createExpressionPlusOne with more general addToNumericExpression
ark120202 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| function __TS__StringAccess(this: string, index: number) { | ||
| if (index >= 0 && index < this.length) { | ||
| return string.sub(this, index + 1, index + 1); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| function __TS__StringCharAt(this: string, pos: number): string { | ||
| if (pos !== pos) pos = 0; | ||
| if (pos < 0) return ""; | ||
| return string.sub(this, pos + 1, pos + 1); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| function __TS__StringCharCodeAt(this: string, index: number): number { | ||
| if (index !== index) index = 0; | ||
| if (index < 0) return NaN; | ||
| return string.byte(this, index + 1) ?? NaN; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| function __TS__StringSlice(this: string, start?: number, end?: number): string { | ||
| if (start === undefined || start !== start) start = 0; | ||
| if (end !== end) end = 0; | ||
|
|
||
| if (start >= 0) start += 1; | ||
| if (end !== undefined && end < 0) end -= 1; | ||
|
|
||
| return string.sub(this, start, end); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| function __TS__StringSubstr(this: string, from: number, length?: number): string { | ||
| if (from !== from) from = 0; | ||
|
|
||
| if (length !== undefined) { | ||
| if (length !== length || length <= 0) return ""; | ||
| length += from; | ||
| } | ||
|
|
||
| if (from >= 0) from += 1; | ||
|
|
||
| return string.sub(this, from, length); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| function __TS__StringSubstring(this: string, start: number, end?: number): string { | ||
| if (end !== end) end = 0; | ||
|
|
||
| if (end !== undefined && start > end) { | ||
| [start, end] = [end, start]; | ||
| } | ||
|
|
||
| if (start >= 0) { | ||
| start += 1; | ||
| } else { | ||
| start = 1; | ||
| } | ||
|
|
||
| if (end !== undefined && end < 0) end = 0; | ||
|
|
||
| return string.sub(this, start, end); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.