////////////////////////////////////////////////////////////////////////////////
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You 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.
//
////////////////////////////////////////////////////////////////////////////////
package flashx.textLayout.utils
{
/**
* Utilities for managing and getting information about characters.
* The methods of this class are static and must be called using
* the syntax CharacterUtil.method(parameter)
.
*
* @playerversion Flash 10
* @playerversion AIR 1.5
* @langversion 3.0
*/
public final class CharacterUtil
{
/**
* Returns true
if the charCode
argument is a high word in a surrogate pair.
* A surrogate pair represents a character with a code point that requires more
* than sixteen bits to express and thus requires a combination
* of two 16-bit words, a high surrogate and a low surrogate, to embody its code point.
*
This method can be used when processing a series of characters to * ensure that you do not inadvertently divide a surrogate pair * into incomplete halves.
* * * @param charCode An integer that represents a character code. * Character codes are usually represented in hexadecimal format. * For example, the space character's character code can be * represented by the number0x0020
.
* @return true
if charCode
is the high surrogate in a surrogate pair.
* @playerversion Flash 10
* @playerversion AIR 1.5
* @langversion 3.0
*/
static public function isHighSurrogate(charCode:int):Boolean
{
return (charCode >= 0xD800 && charCode <= 0xDBFF);
}
/**
* Returns true
if the charCode
argument is a low word in a surrogate pair.
* A surrogate pair represents a character with a code point that requires more
* than sixteen bits to express and thus requires a combination
* of two 16-bit words, a high surrogate and a low surrogate, to embody its code point.
* This method can be used when processing a series of characters to * ensure that you do not inadvertently divide a surrogate pair * into incomplete halves.
* * @param charCode An integer that represents a character code. * Character codes are usually represented in hexadecimal format. * For example, the space character's character code can be * represented by the number0x0020
.
* @return true
if charCode
is the low surrogate in a surrogate pair.
* @playerversion Flash 10
* @playerversion AIR 1.5
* @langversion 3.0
*/
static public function isLowSurrogate (charCode:int):Boolean
{
return (charCode >= 0xDC00 && charCode <= 0xDFFF);
}
static private var whiteSpaceObject:Object = createWhiteSpaceObject();
static private function createWhiteSpaceObject():Object
{
var rslt:Object = new Object();
//members of SpaceSeparator category
rslt[0x0020] = true; //SPACE
rslt[0x1680] = true; //OGHAM SPACE MARK
rslt[0x180E] = true; //MONGOLIAN VOWEL SEPARATOR
rslt[0x2000] = true; //EN QUAD
rslt[0x2001] = true; //EM QUAD
rslt[0x2002] = true; //EN SPACE
rslt[0x2003] = true; //EM SPACE
rslt[0x2004] = true; //THREE-PER-EM SPACE
rslt[0x2005] = true; //FOUR-PER-EM SPACE
rslt[0x2006] = true; //SIZE-PER-EM SPACE
rslt[0x2007] = true; //FIGURE SPACE
rslt[0x2008] = true; //PUNCTUATION SPACE
rslt[0x2009] = true; //THIN SPACE
rslt[0x200A] = true; //HAIR SPACE
rslt[0x202F] = true; //NARROW NO-BREAK SPACE
rslt[0x205F] = true; //MEDIUM MATHEMATICAL SPACE
rslt[0x3000] = true; //IDEOGRAPHIC SPACE
//members of LineSeparator category
rslt[0x2028] = true; //LINE SEPARATOR
//members of ParagraphSeparator category
rslt[0x2029] = true;
//Other characters considered to be a space
rslt[0x0009] = true; //CHARACTER TABULATION
rslt[0x000A] = true; //LINE FEED
rslt[0x000B] = true; //LINE TABULATION
rslt[0x000C] = true; //FORM FEED
rslt[0x000D] = true; //CARRIAGE RETURN
rslt[0x0085] = true; //NEXT LINE
rslt[0x00A0] = true; //NO-BREAK SPACE
return rslt;
}
/**
* Returns true
if charCode
is a whitespace character.
* The following table describes all characters that this * method considers a whitespace character. *
*Character Code | Unicode Character Name | Category |
---|---|---|
0x0020 | SPACE | Space Separator |
0x1680 | OGHAM SPACE MARK | Space Separator |
0x180E | MONGOLIAN VOWEL SEPARATOR | Space Separator |
0x2000 | EN QUAD | Space Separator |
0x2001 | EM QUAD | Space Separator |
0x2002 | EN SPACE | Space Separator |
0x2003 | EM SPACE | Space Separator |
0x2004 | THREE-PER-EM SPACE | Space Separator |
0x2005 | FOUR-PER-EM SPACE | Space Separator |
0x2006 | SIX-PER-EM SPACE | Space Separator |
0x2007 | FIGURE SPACE | Space Separator |
0x2008 | PUNCTUATION SPACE | Space Separator |
0x2009 | THIN SPACE | Space Separator |
0x200A | HAIR SPACE | Space Separator |
0x202F | NARROW NO-BREAK SPACE | Space Separator |
0x205F | MEDIUM MATHEMATICAL SPACE | Space Separator |
0x3000 | IDEOGRAPHIC SPACE | Space Separator |
0x2028 | LINE SEPARATOR | Line Separator |
0x2029 | PARAGRAPH SEPARATOR | Paragraph Separator |
0x0009 | CHARACTER TABULATION | Other |
0x000A | LINE FEED | Other |
0x000B | LINE TABULATION | Other |
0x000C | FORM FEED | Other |
0x000D | CARRIAGE RETURN | Other |
0x0085 | NEXT LINE | Other |
0x00A0 | NO-BREAK SPACE | Other |
0x0020
.
*
* @return true
if charCode
is a whitespace character.
* @playerversion Flash 10
* @playerversion AIR 1.5
* @langversion 3.0
*/
static public function isWhitespace(charCode:int):Boolean
{
return whiteSpaceObject[charCode];
}
}
}