Use inverse upcase instead of downcase per ECMA-262 for case-insensitive matching, r=dmandelin

This commit is contained in:
Steve Harper 2009-12-23 18:48:53 -08:00
parent 9bb4ee55a9
commit a4bcebed1c
3 changed files with 80 additions and 14 deletions

View File

@ -375,17 +375,15 @@ upcase(uintN ch)
return (cu < 128) ? ch : cu;
}
static JS_ALWAYS_INLINE uintN
downcase(uintN ch)
/*
* Return the 'canonical' inverse upcase of |ch|. That is the character
* |lch| such that |upcase(lch) == ch| and (|lch| is the lower-case form
* of |ch| or is |ch|).
*/
static inline jschar inverse_upcase(jschar ch)
{
JS_ASSERT((uintN) (jschar) ch == ch);
if (ch < 128) {
if (ch - (uintN) 'A' <= (uintN) ('Z' - 'A'))
ch += (uintN) ('a' - 'A');
return ch;
}
return JS_TOLOWER(ch);
jschar lch = JS_TOLOWER(ch);
return upcase(lch) == ch ? lch : ch;
}
/* Construct and initialize an RENode, returning NULL for out-of-memory */
@ -1090,7 +1088,7 @@ lexHex:
jschar uch, dch;
uch = upcase(i);
dch = downcase(i);
dch = inverse_upcase(i);
maxch = JS_MAX(maxch, uch);
maxch = JS_MAX(maxch, dch);
}
@ -2360,7 +2358,7 @@ class RegExpNativeCompiler {
if (cs->flags & JSREG_FOLD) {
ch = JS_TOUPPER(ch);
jschar lch = JS_TOLOWER(ch);
jschar lch = inverse_upcase(ch);
if (ch != lch) {
if (L'A' <= ch && ch <= L'Z') {
@ -3884,7 +3882,7 @@ ProcessCharSet(JSContext *cx, JSRegExp *re, RECharSet *charSet)
AddCharacterToCharSet(charSet, i);
uch = upcase(i);
dch = downcase(i);
dch = inverse_upcase(i);
if (i != uch)
AddCharacterToCharSet(charSet, uch);
if (i != dch)
@ -3897,7 +3895,7 @@ ProcessCharSet(JSContext *cx, JSRegExp *re, RECharSet *charSet)
} else {
if (re->flags & JSREG_FOLD) {
AddCharacterToCharSet(charSet, upcase(thisCh));
AddCharacterToCharSet(charSet, downcase(thisCh));
AddCharacterToCharSet(charSet, inverse_upcase(thisCh));
} else {
AddCharacterToCharSet(charSet, thisCh);
}

View File

@ -250,6 +250,7 @@ script regress-426827.js
script regress-428366.js
script regress-438415-01.js
script regress-438415-02.js
script regress-440926.js
script regress-449627.js
script regress-449666.js
script regress-450369.js

View File

@ -0,0 +1,67 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is JavaScript Engine testing utilities.
*
* The Initial Developer of the Original Code is
* Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Dave Mandelin
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
var gTestfile = 'regress-440926.js';
//-----------------------------------------------------------------------------
var BUGNUMBER = 440926;
var summary = 'Correctly match regexps with special "i" characters';
var actual = '';
var expect = 'iI#,iI#;iI#,iI#';
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
enterFunc ('test');
printBugNumber(BUGNUMBER);
printStatus (summary);
actual += 'iI\u0130'.replace(/[\u0130]/gi, '#');
actual += ',' + 'iI\u0130'.replace(/\u0130/gi, '#');
jit(true);
actual += ';' + 'iI\u0130'.replace(/[\u0130]/gi, '#');
actual += ',' + 'iI\u0130'.replace(/\u0130/gi, '#');
jit(false);
reportCompare(expect, actual, summary);
exitFunc ('test');
}