-
Notifications
You must be signed in to change notification settings - Fork 684
Implement toLowerCase and toUpperCase built-in functions. #365
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
Closed
Closed
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -328,3 +328,79 @@ lit_char_is_word_char (ecma_char_t c) /**< code unit */ | |
|| (c >= LIT_CHAR_ASCII_DIGITS_BEGIN && c <= LIT_CHAR_ASCII_DIGITS_END) | ||
|| c == LIT_CHAR_UNDERSCORE); | ||
} /* lit_char_is_word_char */ | ||
|
||
/** | ||
* Returns the lowercase character sequence of an ecma character. | ||
* | ||
* Note: output_buffer_p must be able to hold at least LIT_MAXIMUM_OTHER_CASE_LENGTH characters. | ||
* | ||
* @return the length of the lowercase character sequence | ||
* which is always between 1 and LIT_MAXIMUM_OTHER_CASE_LENGTH. | ||
*/ | ||
lit_utf8_size_t | ||
lit_char_to_lower_case (ecma_char_t character, /**< input character value */ | ||
ecma_char_t *output_buffer_p, /**< buffer for the result characters */ | ||
size_t buffer_size) /**< buffer size */ | ||
{ | ||
TODO ("Needs a proper lower case implementation. See issue #323."); | ||
|
||
JERRY_ASSERT (buffer_size >= LIT_MAXIMUM_OTHER_CASE_LENGTH); | ||
|
||
if (character >= LIT_CHAR_UPPERCASE_A && character <= LIT_CHAR_UPPERCASE_Z) | ||
{ | ||
output_buffer_p[0] = (ecma_char_t) (character + (LIT_CHAR_LOWERCASE_A - LIT_CHAR_UPPERCASE_A)); | ||
return 1; | ||
} | ||
|
||
if (character == 0x130) | ||
{ | ||
output_buffer_p[0] = LIT_CHAR_LOWERCASE_I; | ||
output_buffer_p[1] = 0x307; | ||
return 2; | ||
} | ||
|
||
output_buffer_p[0] = character; | ||
return 1; | ||
} /* lit_char_to_lower_case */ | ||
|
||
/** | ||
* Returns the uppercase character sequence of an ecma character. | ||
* | ||
* Note: output_buffer_p must be able to hold at least LIT_MAXIMUM_OTHER_CASE_LENGTH characters. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zherczeg, could you, please, also update the function likewise? |
||
* | ||
* @return the length of the uppercase character sequence | ||
* which is always between 1 and LIT_MAXIMUM_OTHER_CASE_LENGTH. | ||
*/ | ||
lit_utf8_size_t | ||
lit_char_to_upper_case (ecma_char_t character, /**< input character value */ | ||
ecma_char_t *output_buffer_p, /**< buffer for the result characters */ | ||
size_t buffer_size) /**< buffer size */ | ||
{ | ||
TODO ("Needs a proper upper case implementation. See issue #323."); | ||
|
||
JERRY_ASSERT (buffer_size >= LIT_MAXIMUM_OTHER_CASE_LENGTH); | ||
|
||
if (character >= LIT_CHAR_LOWERCASE_A && character <= LIT_CHAR_LOWERCASE_Z) | ||
{ | ||
output_buffer_p[0] = (ecma_char_t) (character - (LIT_CHAR_LOWERCASE_A - LIT_CHAR_UPPERCASE_A)); | ||
return 1; | ||
} | ||
|
||
if (character == 0xdf) | ||
{ | ||
output_buffer_p[0] = LIT_CHAR_UPPERCASE_S; | ||
output_buffer_p[1] = LIT_CHAR_UPPERCASE_S; | ||
return 2; | ||
} | ||
|
||
if (character == 0x1fd7) | ||
{ | ||
output_buffer_p[0] = 0x399; | ||
output_buffer_p[1] = 0x308; | ||
output_buffer_p[2] = 0x342; | ||
return 3; | ||
} | ||
|
||
output_buffer_p[0] = character; | ||
return 1; | ||
} /* lit_char_to_upper_case */ |
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,55 @@ | ||
// Copyright 2015 University of Szeged | ||
// Copyright 2015 Samsung Electronics Co., Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Conversion | ||
|
||
assert ("0123456789abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXYZ".toLowerCase() | ||
== "0123456789abcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxyz"); | ||
assert ("0123456789abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXYZ".toUpperCase() | ||
== "0123456789ABCDEFGHIJKLMNOPQRSTUVWXZYABCDEFGHIJKLMNOPQRSTUVWXYZ"); | ||
|
||
assert ("\u0130".toLowerCase() == "i\u0307"); | ||
assert ("\xdf".toUpperCase() == "SS"); | ||
assert ("\u1fd7".toUpperCase() == "\u0399\u0308\u0342"); | ||
|
||
assert ("H\u0130-+".toLowerCase() == "hi\u0307-+"); | ||
assert ("\xdf\u1fd7\xdf".toUpperCase() == "SS\u0399\u0308\u0342SS"); | ||
assert ("\u0130\u0130\u0130".toLowerCase() == "i\u0307i\u0307i\u0307"); | ||
|
||
// Although codepoint 0x10400 and 0x10428 are an upper-lowercase pair, | ||
// we must not do their conversion in JavaScript. We must also ignore | ||
// stray surrogates. | ||
|
||
assert ("\ud801\ud801\udc00\udc00".toLowerCase() == "\ud801\ud801\udc00\udc00"); | ||
assert ("\ud801\ud801\udc28\udc28".toUpperCase() == "\ud801\ud801\udc28\udc28"); | ||
|
||
// Conversion of non-string objects. | ||
|
||
assert (String.prototype.toUpperCase.call(true) == "TRUE"); | ||
assert (String.prototype.toLowerCase.call(-23) == "-23"); | ||
|
||
var object = { toString : function() { return "<sTr>"; } }; | ||
assert (String.prototype.toUpperCase.call(object) == "<STR>"); | ||
assert (String.prototype.toLowerCase.call(object) == "<str>"); | ||
|
||
try | ||
{ | ||
String.prototype.toUpperCase.call(null); | ||
assert(false); | ||
} | ||
catch (e) | ||
{ | ||
assert (e instanceof TypeError); | ||
} |
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.
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.
@zherczeg, could you, please, add arguments like
buffer_size
to the function, and check the condition withJERRY_ASSERT
?