Class StringMapper
Create a new string mapper instance.
The options may contain any of the following properties:
- locale - locale to use when loading the mapper. Some maps are locale-dependent, and this locale selects the right one. Default if this is not specified is the current locale.
- name - the name of the map to load
- mapFunction - specify an algorithmic mapping function to use if the mapper does not have an explicit mapping for a character. The idea is to save disk and memory when algorithmic mapping can be done for some of the characters, but not others. The exceptions can go into the json file, and the characters that conform to the rule can be mapped algorithmically. The map function should take a string containing 1 character as a parameter and should return a string containing one or more characters. If the character is outside of the range that can be mapped, it should be returned unchanged.
- onLoad - a callback function to call when this object is fully loaded. When the onLoad option is given, this object will attempt to load any missing locale data using the ilib loader callback. When the constructor is done (even if the data is already preassembled), the onLoad function is called with the current instance as a parameter, so this callback can be used with preassembled or dynamic loading or a mix of the two.
- sync - tell whether to load any missing locale data synchronously or asynchronously. If this option is given as "false", then the "onLoad" callback must be given, as the instance returned from this constructor will not be usable for a while.
- loadParams - an object containing parameters to pass to the loader callback function when locale data is missing. The parameters are not interpretted or modified in any way. They are simply passed along. The object may contain any property/value pairs as long as the calling code is in agreement with the loader callback function as to what those parameters mean.
Defined in: StringMapper.js.
Constructor Attributes | Constructor Name and Description |
---|---|
StringMapper(options)
|
Method Attributes | Method Name and Description |
---|---|
Return the locale that this mapper was constructed.
|
|
map(string)
Map a string using the mapping defined in the constructor.
|
Class Detail
StringMapper(options)
- Parameters:
- {Object=} options
- options to initialize this string mapper
Method Detail
getLocale()
Return the locale that this mapper was constructed.
- Returns:
{string|IString|undefined}
map(string)
Map a string using the mapping defined in the constructor. This method
iterates through all characters in the string and maps them one-by-one.
If a particular character has a mapping, the mapping result will be
added to the output. If there is no mapping, but there is a mapFunction
defined, the mapFunction results will be added to the result. Otherwise,
the original character from the input string will be added to the result.
- Parameters:
- {string|IString|undefined} string
- Returns:
- {string|IString|undefined}