[ Pobierz całość w formacie PDF ]
1. Let S = ToString(this).
2. Let A be a new array created as if by the expressionnew Array().
3. If limit is undefined, let lim = 232 1; else let lim = ToUint32(limit).
4. Let s be the number of characters in S.
5. Let p = 0.
6. If separator is a RegExp object (its [[Class]] is"RegExp"), let R = separator; otherwise let R =
ToString(separator).
7. If lim = 0, return A.
8. If separator is undefined, go to step 33.
9. If s = 0, go to step 31.
10. Let q = p.
11. If q = s, go to step 28.
12. Call SplitMatch(R, S, q) and let z be its MatchResult result.
13. If z is failure, go to step 26.
14. z must be a State. Let e be z's endIndex and let cap be z's captures array.
15. If e = p, go to step 26.
16. Let T be a string value equal to the substring of S consisting of the characters at positions p
(inclusive) through q (exclusive).
17. Call the [[Put]] method of A with arguments A.length and T.
18. If A.length = lim, return A.
19. Let p = e.
20. Let i = 0.
21. If i is equal to the number of elements in cap, go to step 10.
22. Let i = i+1.
23. Call the [[Put]] method of A with arguments A.length and cap[i].
24. If A.length= lim, return A.
25. Go to step 21.
26. Let q = q+1.
27. Go to step 11.
28. Let T be a string value equal to the substring of S consisting of the characters at positions p
(inclusive) through s (exclusive).
29. Call the [[Put]] method of A with arguments A.length and T.
30. Return A.
31. Call SplitMatch(R, S, 0) and let z be its MatchResult result.
32. If z is not failure, return A.
33. Call the [[Put]] method of A with arguments"0" and S.
34. Return A.
The internal helper function SplitMatch takes three parameters, a string S, an integer q, and a string or
RegExp R, and performs the following in order to return a MatchResult (see 15.10.2.1):
1. If R is a RegExp object (its [[Class]] is"RegExp"), go to step 8.
2. R must be a string. Let r be the number of characters in R.
3. Let s be the number of characters in S.
4. If q+r > s then return the MatchResult failure.
5. If there exists an integer i between 0 (inclusive) and r (exclusive) such that the character at
position q+i of S is different from the character at position i of R, then return failure.
6. Let cap be an empty array of captures (see 15.10.2.1).
7. Return the State (q+r, cap). (see 15.10.2.1)
8. Call the [[Match]] method of R giving it the arguments S and q, and return the MatchResult result.
- 105 -
Thelengthproperty of thesplitmethod is 2.
NOTE 1
Thesplitfunction is intentionally generic; it does not require that its this value be a String object.
Therefore, it can be transferred to other kinds of objects for use as a method.
NOTE 2
Thesplitmethod ignores the value of separator.globalfor separators that are RegExp objects.
15.5.4.15 String.prototype.substring (start, end)
The substring method takes two arguments, start and end, and returns a substring of the result of
converting this object to a string, starting from character position start and running to, but not
including, character position end of the string (or through the end of the string is end is undefined).
The result is a string value, not a String object.
If either argument is NaN or negative, it is replaced with zero; if either argument is larger than the
length of the string, it is replaced with the length of the string.
If start is larger than end, they are swapped.
The following steps are taken:
1. Call ToString, giving it the this value as its argument.
2. Compute the number of characters in Result(1).
3. Call ToInteger(start).
4. If end is undefined, use Result(2); else use ToInteger(end).
5. Compute min(max(Result(3), 0), Result(2)).
6. Compute min(max(Result(4), 0), Result(2)).
7. Compute min(Result(5), Result(6)).
8. Compute max(Result(5), Result(6)).
9. Return a string whose length is the difference between Result(8) and Result(7), containing
characters from Result(1), namely the characters with indices Result(7) through Result(8)-1, in
ascending order.
Thelengthproperty of thesubstringmethod is 2.
NOTE
Thesubstringfunction is intentionally generic; it does not require that its this value be a String
object. Therefore, it can be transferred to other kinds of objects for use as a method.
15.5.4.16 String.prototype.toLowerCase ( )
If this object is not already a string, it is converted to a string. The characters in that string are
converted one by one to lower case. The result is a string value, not a String object.
The characters are converted one by one. The result of each conversion is the original character,
unless that character has a Unicode lowercase equivalent, in which case the lowercase equivalent is
used instead.
NOTE 1
The result should be derived according to the case mappings in the Unicode character database (this
explicitly includes not only the UnicodeData.txt file, but also the SpecialCasings.txt file that
accompanies it in Unicode 2.1.8 and later).
NOTE 2
The toLowerCase function is intentionally generic; it does not require that its this value be a
String object. Therefore, it can be transferred to other kinds of objects for use as a method.
15.5.4.17 String.prototype.toLocaleLowerCase ( )
This function works exactly the same astoLowerCaseexcept that its result is intended to yield the
correct result for the host environment s current locale, rather than a locale-independent result. There
will only be a difference in the few cases (such as Turkish) where the rules for that language conflict
with the regular Unicode case mappings.
- 106 -
NOTE 1
ThetoLocaleLowerCasefunction is intentionally generic; it does not require that its this value
be a String object. Therefore, it can be transferred to other kinds of objects for use as a method.
NOTE 2
The first parameter to this function is likely to be used in a future version of this standard; it is
recommended that implementations do not use this parameter position for anything else.
15.5.4.18 String.prototype.toUpperCase ( )
This function behaves in exactly the same way asString.prototype.toLowerCase, except
that characters are mapped to their uppercase equivalents as specified in the Unicode Character
Database.
NOTE 1
Because both toUpperCaseand toLowerCasehave context-sensitive behaviour, the functions
are not symmetrical. In other words, s.toUpperCase().toLowerCase() is not necessarily
equal tos.toLowerCase().
NOTE 2
The toUpperCase function is intentionally generic; it does not require that its this value be a
String object. Therefore, it can be transferred to other kinds of objects for use as a method.
15.5.4.19 String.prototype.toLocaleUpperCase ( )
This function works exactly the same astoUpperCaseexcept that its result is intended to yield the
correct result for the host environment s current locale, rather than a locale-independent result. There
will only be a difference in the few cases (such as Turkish) where the rules for that language conflict
with the regular Unicode case mappings.
NOTE 1
ThetoLocaleUpperCasefunction is intentionally generic; it does not require that its this value
be a String object. Therefore, it can be transferred to other kinds of objects for use as a method.
NOTE 2
The first parameter to this function is likely to be used in a future version of this standard; it is
recommended that implementations do not use this parameter position for anything else.
15.5.5 Properties of String Instances
String instances inherit properties from the String prototype object and also have a [[Value]] property
and alengthproperty.
[ Pobierz całość w formacie PDF ]