зеркало из https://github.com/mozilla/pjs.git
added libnls headers to public build
This commit is contained in:
Родитель
9b1599e358
Коммит
a374494452
|
@ -0,0 +1,283 @@
|
|||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1997 *
|
||||
* (C) Copyright International Business Machines Corporation, 1997 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
*
|
||||
* File BRKITER.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/18/97 aliu Added typedef for TextCount. Made DONE const.
|
||||
* 05/07/97 aliu Fixed DLL declaration.
|
||||
* 07/09/97 jfitz Renamed BreakIterator and interface synced with JDK
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _BRKITER
|
||||
#define _BRKITER
|
||||
|
||||
#include "unistring.h"
|
||||
#include "locid.h"
|
||||
class Locale;
|
||||
|
||||
/**
|
||||
* The BreakIterator class implements methods for finding the location
|
||||
* of boundaries in text. BreakIterator is an abstract base class.
|
||||
* Instances of BreakIterator maintain a current position and scan over
|
||||
* text returning the index of characters where boundaries occur.
|
||||
* <P>
|
||||
* Line boundary analysis determines where a text string can be broken
|
||||
* when line-wrapping. The mechanism correctly handles punctuation and
|
||||
* hyphenated words.
|
||||
* <P>
|
||||
* Sentence boundary analysis allows selection with correct
|
||||
* interpretation of periods within numbers and abbreviations, and
|
||||
* trailing punctuation marks such as quotation marks and parentheses.
|
||||
* <P>
|
||||
* Word boundary analysis is used by search and replace functions, as
|
||||
* well as within text editing applications that allow the user to
|
||||
* select words with a double click. Word selection provides correct
|
||||
* interpretation of punctuation marks within and following
|
||||
* words. Characters that are not part of a word, such as symbols or
|
||||
* punctuation marks, have word-breaks on both sides.
|
||||
* <P>
|
||||
* Character boundary analysis allows users to interact with
|
||||
* characters as they expect to, for example, when moving the cursor
|
||||
* through a text string. Character boundary analysis provides correct
|
||||
* navigation of through character strings, regardless of how the
|
||||
* character is stored. For example, an accented character might be
|
||||
* stored as a base character and a diacritical mark. What users
|
||||
* consider to be a character can differ between languages.
|
||||
* <P>
|
||||
* This is the interface for all text boundaries.
|
||||
* <P>
|
||||
* Examples:
|
||||
* <P>
|
||||
* Print each element in order:
|
||||
* <pre>
|
||||
* . void printEachForward(const BreakIterator& boundary) {
|
||||
* . UnicodeString textChunk;
|
||||
* . TextOffset start = boundary.first();
|
||||
* . for (TextOffset end = boundary.next();
|
||||
* . end != BreakIterator::DONE;
|
||||
* . start = end, end = boundary.next())
|
||||
* . {
|
||||
* . cout << boundary.getText()->extract(start, end, textChunk);
|
||||
* . }
|
||||
* . }
|
||||
* </pre>
|
||||
* Print each element in reverse order:
|
||||
* <pre>
|
||||
* . void printEachbackward(const BreakIterator& boundary) {
|
||||
* . UnicodeString textChunk;
|
||||
* . TextOffset end = boundary.last();
|
||||
* . for (TextOffset start = boundary.previous();
|
||||
* . start != BreakIterator::DONE;
|
||||
* . end = start, start = boundary.previous())
|
||||
* . {
|
||||
* . cout << boundary.getText()->extract(start, end, textChunk);
|
||||
* . }
|
||||
* . }
|
||||
* </pre>
|
||||
*/
|
||||
class T_FINDWORD_API BreakIterator {
|
||||
public:
|
||||
virtual ~BreakIterator();
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically equal to this
|
||||
* one. The other object should be an instance of the same subclass of
|
||||
* BreakIterator. Objects of different subclasses are considered
|
||||
* unequal.
|
||||
* <P>
|
||||
* Return true if this BreakIterator is at the same position in the
|
||||
* same text, and is the same class and type (word, line, etc.) of
|
||||
* BreakIterator, as the argument. Text is considered the same if
|
||||
* it contains the same characters, it need not be the same
|
||||
* object, and styles are not considered.
|
||||
*/
|
||||
virtual t_bool operator==(const BreakIterator&) const = 0;
|
||||
|
||||
t_bool operator!=(const BreakIterator& rhs) const { return !operator==(rhs); }
|
||||
|
||||
/**
|
||||
* Return a polymorphic copy of this object. This is an abstract
|
||||
* method which subclasses implement.
|
||||
*/
|
||||
virtual BreakIterator* clone() const = 0;
|
||||
|
||||
/**
|
||||
* Return a polymorphic class ID for this object. Different subclasses
|
||||
* will return distinct unequal values.
|
||||
*/
|
||||
virtual ClassID getDynamicClassID() const = 0;
|
||||
|
||||
/**
|
||||
* Get the text for which this object is finding the boundaries.
|
||||
*/
|
||||
virtual const UnicodeString* getText() const = 0;
|
||||
|
||||
/**
|
||||
* Set the text for which this object should find the boundaries.
|
||||
*/
|
||||
virtual void setText(const UnicodeString*) = 0;
|
||||
|
||||
/**
|
||||
* DONE is returned by previous() and next() after all valid
|
||||
* boundaries have been returned.
|
||||
*/
|
||||
static const TextOffset DONE;
|
||||
|
||||
/**
|
||||
* Return the index of the first character in the text being scanned.
|
||||
*/
|
||||
virtual TextOffset first() = 0;
|
||||
|
||||
/**
|
||||
* Return the index immediately BEYOND the last character in the text being scanned.
|
||||
*/
|
||||
virtual TextOffset last() = 0;
|
||||
|
||||
/**
|
||||
* Return the boundary preceding the current boundary.
|
||||
* @return The character index of the previous text boundary or DONE if all
|
||||
* boundaries have been returned.
|
||||
*/
|
||||
virtual TextOffset previous() = 0;
|
||||
|
||||
/**
|
||||
* Return the boundary following the current boundary.
|
||||
* @return The character index of the next text boundary or DONE if all
|
||||
* boundaries have been returned.
|
||||
*/
|
||||
virtual TextOffset next() = 0;
|
||||
|
||||
/**
|
||||
* Return character index of the text boundary that was most recently
|
||||
* returned by next(), previous(), first(), or last()
|
||||
* @return The boundary most recently returned.
|
||||
*/
|
||||
virtual TextOffset current() const = 0;
|
||||
|
||||
/**
|
||||
* Return the first boundary following the specified offset.
|
||||
* The value returned is always greater than the offset or
|
||||
* the value BreakIterator.DONE
|
||||
* @param offset the offset to begin scanning.
|
||||
* @return The first boundary after the specified offset.
|
||||
*/
|
||||
virtual TextOffset following(TextOffset offset) = 0;
|
||||
|
||||
/**
|
||||
* Return the nth boundary from the current boundary
|
||||
* @param n which boundary to return. A value of 0
|
||||
* does nothing. Negative values move to previous boundaries
|
||||
* and positive values move to later boundaries.
|
||||
* @return The index of the nth boundary from the current position, or
|
||||
* DONE if there are fewer than |n| boundaries in the specfied direction.
|
||||
*/
|
||||
virtual TextOffset next(t_int32 n) = 0;
|
||||
|
||||
/**
|
||||
* Create BreakIterator for word-breaks using the given locale.
|
||||
* Returns an instance of a BreakIterator implementing word breaks.
|
||||
* WordBreak is useful for word selection (ex. double click)
|
||||
* @param where the locale. If a specific WordBreak is not
|
||||
* avaliable for the specified locale, a default WordBreak is returned.
|
||||
* @return A BreakIterator for word-breaks
|
||||
*/
|
||||
static BreakIterator* createWordInstance(const Locale& where = Locale::getDefault());
|
||||
|
||||
/**
|
||||
* Create BreakIterator for line-breaks using specified locale.
|
||||
* Returns an instance of a BreakIterator implementing line breaks. Line
|
||||
* breaks are logically possible line breaks, actual line breaks are
|
||||
* usually determined based on display width.
|
||||
* LineBreak is useful for word wrapping text.
|
||||
* @param where the locale. If a specific LineBreak is not
|
||||
* avaliable for the specified locale, a default LineBreak is returned.
|
||||
* @return A BreakIterator for line-breaks
|
||||
*/
|
||||
static BreakIterator* createLineInstance(const Locale& where = Locale::getDefault());
|
||||
|
||||
/**
|
||||
* Create BreakIterator for character-breaks using specified locale
|
||||
* Returns an instance of a BreakIterator implementing character breaks.
|
||||
* Character breaks are boundaries of combining character sequences.
|
||||
* @param where the locale. If a specific character break is not
|
||||
* avaliable for the specified locale, a default character break is returned.
|
||||
* @return A BreakIterator for character-breaks
|
||||
*/
|
||||
static BreakIterator* createCharacterInstance(const Locale& where = Locale::getDefault());
|
||||
|
||||
/**
|
||||
* Create BreakIterator for sentence-breaks using specified locale
|
||||
* Returns an instance of a BreakIterator implementing sentence breaks.
|
||||
* @param where the locale. If a specific SentenceBreak is not
|
||||
* avaliable for the specified locale, a default SentenceBreak is returned.
|
||||
* @return A BreakIterator for sentence-breaks
|
||||
*/
|
||||
static BreakIterator* createSentenceInstance(const Locale& where = Locale::getDefault());
|
||||
|
||||
/**
|
||||
* Get the set of Locales for which TextBoundaries are installed
|
||||
* @param count the output parameter of number of elements in the locale list
|
||||
* @return available locales
|
||||
*/
|
||||
static const Locale* getAvailableLocales(t_int32& count);
|
||||
|
||||
/**
|
||||
* Get name of the object for the desired Locale, in the desired langauge.
|
||||
* @param objectLocale must be from getAvailableLocales.
|
||||
* @param displayLocale specifies the desired locale for output.
|
||||
* @param name the fill-in parameter of the return value
|
||||
* Uses best match.
|
||||
* @return user-displayable name
|
||||
*/
|
||||
static UnicodeString& getDisplayName(const Locale& objectLocale,
|
||||
const Locale& displayLocale,
|
||||
UnicodeString& name);
|
||||
|
||||
/**
|
||||
* Get name of the object for the desired Locale, in the langauge of the
|
||||
* default locale.
|
||||
* @param objectLocale must be from getMatchingLocales
|
||||
* @param name the fill-in parameter of the return value
|
||||
* @return user-displayable name
|
||||
*/
|
||||
static UnicodeString& getDisplayName(const Locale& objectLocale,
|
||||
UnicodeString& name);
|
||||
|
||||
|
||||
|
||||
// begin deprecated api.
|
||||
virtual TextOffset nextAfter(TextOffset offset) = 0;
|
||||
virtual TextOffset nthFromCurrent(t_int32 n) = 0;
|
||||
static BreakIterator* createWordBreak(const Locale& where = Locale::getDefault()) { return createWordInstance(); }
|
||||
static BreakIterator* createLineBreak(const Locale& where = Locale::getDefault()) { return createLineInstance(); }
|
||||
static BreakIterator* createCharacterBreak(const Locale& where = Locale::getDefault()) { return createCharacterInstance(); }
|
||||
static BreakIterator* createSentenceBreak(const Locale& where = Locale::getDefault()) { return createSentenceInstance(); }
|
||||
// end deprecated api.
|
||||
|
||||
protected:
|
||||
BreakIterator();
|
||||
|
||||
private:
|
||||
/**
|
||||
* The copy constructor and assignment operator have no real implementation.
|
||||
* They are provided to make the compiler happy. Do not call.
|
||||
*/
|
||||
BreakIterator& operator=(const BreakIterator& other) { return *this; }
|
||||
BreakIterator (const BreakIterator& other) {}
|
||||
};
|
||||
|
||||
#endif // _BRKITER
|
||||
//eof
|
|
@ -0,0 +1,664 @@
|
|||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1996 *
|
||||
* (C) Copyright International Business Machines Corporation, 1996 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
*/
|
||||
//===============================================================================
|
||||
//
|
||||
// File coll.h
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by: Helena Shih
|
||||
//
|
||||
// Modification History:
|
||||
//
|
||||
// Date Name Description
|
||||
// 02/5/97 aliu Modified createDefault to load collation data from
|
||||
// binary files when possible. Added related methods
|
||||
// createCollationFromFile, chopLocale, createPathName.
|
||||
// 02/11/97 aliu Added members addToCache, findInCache, and fgCache.
|
||||
// 02/12/97 aliu Modified to create objects from RuleBasedCollator cache.
|
||||
// Moved cache out of Collation class.
|
||||
// 02/13/97 aliu Moved several methods out of this class and into
|
||||
// RuleBasedCollator, with modifications. Modified
|
||||
// createDefault() to call new RuleBasedCollator(Locale&)
|
||||
// constructor. General clean up and documentation.
|
||||
// 02/20/97 helena Added clone, operator==, operator!=, operator=, copy
|
||||
// constructor and getDynamicClassID.
|
||||
// 03/25/97 helena Updated with platform independent data types.
|
||||
// 05/06/97 helena Added memory allocation error detection.
|
||||
// 6/20/97 helena Java class name change.
|
||||
// 09/03/97 helena Added createCollationKeyValues().
|
||||
// 02/10/98 damiba Added compare() with length as parameter.
|
||||
//===============================================================================
|
||||
|
||||
#ifndef _COLL
|
||||
#define _COLL
|
||||
|
||||
|
||||
#ifndef _LOCID
|
||||
#include "locid.h"
|
||||
#endif
|
||||
|
||||
#ifndef _PTYPES
|
||||
#include "ptypes.h"
|
||||
#endif
|
||||
|
||||
#ifndef _UNISTRING
|
||||
#include "unistring.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The Collation class is an abstract class which provides Unicode text
|
||||
* comparison services. Text collation supports language-sensitive
|
||||
* comparison of strings, allowing for text searching and alphabetical
|
||||
* sorting. The collation classes provide a choice of ordering
|
||||
* strength (for example, to ignore or not ignore case differences) and
|
||||
* handle ignored, expanding, and contracting characters.
|
||||
* <p>
|
||||
* Developers don't need to know anything about the collation rules for various
|
||||
* languages. Any features requiring collation can use the collation object
|
||||
* associated with the current default locale, or with a specific locale
|
||||
* (like France or Japan) if appropriate.
|
||||
* <UL TYPE=round>
|
||||
* <LI><strong>Basic Collation</strong>: Correctly sorting strings is
|
||||
* tricky, even in English. The results of a sort must be consistent
|
||||
* ; any differences in strings must always be sorted the same
|
||||
* way. The sort assigns relative priorities to different features of
|
||||
* the text, based on the characters themselves and on the current
|
||||
* ordering strength of the collation object. Correct comparison and
|
||||
* sorting of natural languages requires the following:
|
||||
* <UL TYPE=square>
|
||||
* <LI>Ordering priorities: The first primary difference will
|
||||
* determine the resultant order. No matter what the other
|
||||
* characters are. For example, "cat" < "dog". Some languages
|
||||
* require primary, secondary, and tertiary ordering. For example,
|
||||
* in Czech, case differences are a tertiary difference (A vs. a),
|
||||
* accent differences are a secondary differece (e vs. ê) and
|
||||
* different base letters are a primary difference (d vs. e).
|
||||
* <LI>Group characters: In collating some languages, a sequence of
|
||||
* characters is treated as though it was a single letter of the
|
||||
* alphabet. For example, "cx" < "chx" < "dx".
|
||||
* <LI>Expanding characters: In some languages, a single character
|
||||
* is treated as though it was a sequence of letters of the
|
||||
* alphabet. For example, "aex" < "æx" < "aexx".
|
||||
* <LI>Ignorable characters: Certain characters are ignored when
|
||||
* collating. That is, they are not significant unless there are
|
||||
* other differences in the remainder of the string. For example,
|
||||
* "blackbird" < "black-bird" < "blackbirds"
|
||||
* </UL>
|
||||
* <LI><strong>Localizable Collation</strong>: Different collation objects
|
||||
* associated with various locales handle the differences required
|
||||
* when sorting text strings for different languages.
|
||||
* <LI><strong>Customization</strong>: You can produce a new collation by
|
||||
* adding to or changing an existing one.
|
||||
* </UL>
|
||||
* <p>Because compare()'s algorithm is complex, it is faster to sort long lists
|
||||
* of words by retrieving sort keys or collation keys with getCollationKey().
|
||||
* You can then cache the sort keys and compare them using CollationKey::compareTo().
|
||||
* The following is a list of features of sort key:
|
||||
* <UL Type=round>
|
||||
* <LI>bit-ordered (so you can do bit-wise comparison on sort keys)
|
||||
* <LI>use CollationKey.compareTo to compare sort keys
|
||||
* <LI>faster than direct compare algorithm once the keys are generated
|
||||
* </UL>
|
||||
* <p>Collation subclasses implement different collation rules for different
|
||||
* languages and different applications. (phone book, dictionary, etc.)
|
||||
* <p>Use collation strength parameters, PRIMARY, SECONDARY, TERTIARY, and
|
||||
* IDENTICAL to specify the comparison level.
|
||||
* Each unicode character is assigned ordering priority: primary, secondary,
|
||||
* tertiary and no difference.
|
||||
* <p>Decomposition mode determines how composed characters are handled for
|
||||
* Unicode.
|
||||
* <UL Type=round>
|
||||
* <LI>No Decomposition: With no decomposition, accented characters will
|
||||
* not be sorted correctly; this should only be used if the source
|
||||
* text is guaranteed to have no accented characters.
|
||||
* <LI>Canonical Decomposition : Characters that are canonical variants
|
||||
* according to Unicode 2.0 are decomposed in collation if canonical
|
||||
* decomposition mode is set. This is the default, and is required
|
||||
* for proper collation of accented characters.
|
||||
* <LI>Full Decomposition : With full decomposition, both canonical
|
||||
* variants and compatibility variants are decomposed. This causes
|
||||
* not only accented characters to be sorted, but also characters that
|
||||
* have special formats to be sorted with their norminal form. For
|
||||
* example, the half-width and full-width ASCII and Katakana characters
|
||||
* are then sorted properly.
|
||||
* </UL>
|
||||
* <P>NO_DECOMPOSITION is the fastest, but does not produce correct results,
|
||||
* except for languages that do not use accents. You should generally use at
|
||||
* least CANONICAL_DECOMPOSITION. FULL_DECOMPOSITION decomposes even more
|
||||
* characters. For example, it maps the Japanese half-width kana characters
|
||||
* to their normalized characters. For more information on the precise
|
||||
* mappings used, see http://unicode.org.
|
||||
*
|
||||
* <p>LESS, EQUAL, GREATER identifies the result
|
||||
* of unicode text strings comparison.
|
||||
* <p>Use the static method Collator::createInstance() to instantiate the class
|
||||
* by passing the desired locale as the argument.
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . // Compare two strings in the default locale
|
||||
* . Collator *myCollation = Collator::createInstance(status);
|
||||
* . if (FAILURE(status)) return;
|
||||
* . Collator::EComparisonResult result = myCollation->compare("abc", "ABC");
|
||||
* . delete myCollation;
|
||||
* </pre>
|
||||
* <p>Another example:
|
||||
* <pre>
|
||||
* . // compare two strings in French
|
||||
* . Collator *myCollation = Collator.createInstance(Locale::FRANCE, status);
|
||||
* . if (FAILURE(status)) return;
|
||||
* . Collator::EComparisonResult result = myCollation->compare("abc", "ABC");
|
||||
* </pre>
|
||||
* <p>The following example demonstrates different ways of comparing two
|
||||
* strings:
|
||||
* <pre>
|
||||
* . UnicodeString a("abcdefgh"), b("ijklmnop");
|
||||
*
|
||||
* . // This comparision is not as fast as collation keys.
|
||||
* . // For multiple comparison, use CollationKey. Please see CollationKey
|
||||
* . // class description for more description
|
||||
* . if (myCollation->compare(a, b) == Collator::LESS) { // ... }
|
||||
*
|
||||
* . // Faster than compare when collation keys are cached
|
||||
* . ErrorCode aKeyStatus, bKeyStatus;
|
||||
* . CollationKey aKey, bKey;
|
||||
* . aKey = myCollation->getCollationKey(a, aKey, aKeyStatus);
|
||||
* . bKey = myCollation->getCollationKey(b, bKey, bKeyStatus);
|
||||
* . if (SUCCESS(aKeyStatus)) && SUCCESS(bKeyStatus))
|
||||
* . if (aKey.compareTo(bKey) == Collator::LESS)
|
||||
* . { // ... }
|
||||
*
|
||||
* </pre>
|
||||
* <P><strong>NOTE</strong>: Two collation keys from different collations cannot be
|
||||
* compared. Incorrect comparison result will be returned if you compare
|
||||
* two collation keys from different collators.
|
||||
*
|
||||
* @see RuleBasedCollator
|
||||
* @see CollationKey
|
||||
* @see Locale
|
||||
* @version 1.7 1/14/97
|
||||
* @author Helena Shih
|
||||
*/
|
||||
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
class T_COLLATE_API Collator {
|
||||
public :
|
||||
/**
|
||||
* NO_DECOMPOSITION : Accented characters will not be decomposed for sorting.
|
||||
* Please see class description for more details.
|
||||
* CANONICAL_DECOMPOSITION : Characters that are canonical variants according
|
||||
* to Unicode 2.0 will be decomposed for sorting. This is the default setting.
|
||||
* FULL_DECOMPOSITION : Both canonical variants and compatibility variants be
|
||||
* decomposed for sorting.
|
||||
*/
|
||||
|
||||
enum EDecompositionMode {
|
||||
NO_DECOMPOSITION,
|
||||
CANONICAL_DECOMPOSITION,
|
||||
FULL_DECOMPOSITION
|
||||
};
|
||||
/**
|
||||
* Base letter represents a primary difference. Set comparison
|
||||
* level to PRIMARY to ignore secondary and tertiary differences.
|
||||
* Use this to set the strength of a Collator object.
|
||||
* Example of primary difference, "abc" < "abd"
|
||||
*
|
||||
* Diacritical differences on the same base letter represent a secondary
|
||||
* difference. Set comparison level to SECONDARY to ignore tertiary
|
||||
* differences. Use this to set the strength of a Collator object.
|
||||
* Example of secondary difference, "ä" >> "a".
|
||||
*
|
||||
* Uppercase and lowercase versions of the same character represents a
|
||||
* tertiary difference. Set comparison level to TERTIARY to include
|
||||
* all comparison differences. Use this to set the strength of a Collator
|
||||
* object.
|
||||
* Example of tertiary difference, "abc" <<< "ABC".
|
||||
*
|
||||
* Two characters are considered "identical" when they have the same
|
||||
* unicode spellings.
|
||||
* For example, "ä" == "ä".
|
||||
*
|
||||
* ECollationStrength is also used to determine the strength of sort keys
|
||||
* generated from Collator objects.
|
||||
*/
|
||||
|
||||
|
||||
enum ECollationStrength {
|
||||
PRIMARY,
|
||||
SECONDARY,
|
||||
TERTIARY,
|
||||
IDENTICAL
|
||||
};
|
||||
/**
|
||||
* LESS is returned if source string is compared to be less than target
|
||||
* string in the compare() method.
|
||||
* EQUAL is returned if source string is compared to be equal to target
|
||||
* string in the compare() method.
|
||||
* GREATER is returned if source string is compared to be greater than
|
||||
* target string in the compare() method.
|
||||
* @see Collator#compare
|
||||
*/
|
||||
enum EComparisonResult {
|
||||
LESS = -1,
|
||||
EQUAL = 0,
|
||||
GREATER = 1
|
||||
};
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~Collator();
|
||||
|
||||
/**
|
||||
* Returns true if "other" is the same as "this"
|
||||
*/
|
||||
virtual t_bool operator==(const Collator& other) const;
|
||||
|
||||
/**
|
||||
* Returns true if "other" is not the same as "this".
|
||||
*/
|
||||
virtual t_bool operator!=(const Collator& other) const;
|
||||
|
||||
/**
|
||||
* Makes a shallow copy of the current object.
|
||||
*/
|
||||
virtual Collator* clone() const = 0;
|
||||
/**
|
||||
* Creates the collator object for the current default locale.
|
||||
* The default locale is determined by Locale::getDefault.
|
||||
* @return the collation object of the default locale.(for example, en_US)
|
||||
* @see Locale#getDefault
|
||||
* The ErrorCode& err parameter is used to return status information to the user.
|
||||
* To check whether the construction succeeded or not, you should check
|
||||
* the value of SUCCESS(err). If you wish more detailed information, you
|
||||
* can check for informational error results which still indicate success.
|
||||
* USING_FALLBACK_ERROR indicates that a fall back locale was used. For
|
||||
* example, 'de_CH' was requested, but nothing was found there, so 'de' was
|
||||
* used. USING_DEFAULT_ERROR indicates that the default locale data was
|
||||
* used; neither the requested locale nor any of its fall back locales
|
||||
* could be found.
|
||||
* The caller owns the returned object and is responsible for deleting it.
|
||||
*/
|
||||
static Collator* createInstance( ErrorCode& err);
|
||||
|
||||
/**
|
||||
* Gets the table-based collation object for the desired locale. The
|
||||
* resource of the desired locale will be loaded by ResourceLoader.
|
||||
* Locale::ENGLISH is the base collation table and all other languages are
|
||||
* built on top of it with additional language-specific modifications.
|
||||
* @param desiredLocale the desired locale to create the collation table
|
||||
* with.
|
||||
* @return the created table-based collation object based on the desired
|
||||
* locale.
|
||||
* @see Locale
|
||||
* @see ResourceLoader
|
||||
* The ErrorCode& err parameter is used to return status information to the user.
|
||||
* To check whether the construction succeeded or not, you should check
|
||||
* the value of SUCCESS(err). If you wish more detailed information, you
|
||||
* can check for informational error results which still indicate success.
|
||||
* USING_FALLBACK_ERROR indicates that a fall back locale was used. For
|
||||
* example, 'de_CH' was requested, but nothing was found there, so 'de' was
|
||||
* used. USING_DEFAULT_ERROR indicates that the default locale data was
|
||||
* used; neither the requested locale nor any of its fall back locales
|
||||
* could be found.
|
||||
* The caller owns the returned object and is responsible for deleting it.
|
||||
*/
|
||||
static Collator* createInstance( const Locale& loc,
|
||||
ErrorCode& err);
|
||||
|
||||
/**
|
||||
* The following methods are obsolete in our current APIs. Some methods
|
||||
* were renamed in JDK 1.1. The older versions of the methods will be kept
|
||||
* around for compatibility but will be made obsolete in the future.
|
||||
*/
|
||||
|
||||
// From createInstance
|
||||
static Collator* createDefault(ErrorCode& err);
|
||||
static Collator* createDefault(const Locale& loc,
|
||||
ErrorCode& err);
|
||||
|
||||
// comparison
|
||||
/**
|
||||
* The comparison function compares the character data stored in two
|
||||
* different strings. Returns information about whether a string
|
||||
* is less than, greater than or equal to another string.
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . Collator *myCollation = Collator::createInstance(Locale::US, status);
|
||||
* . if (FAILURE(status)) return;
|
||||
* . myCollation->setStrength(Collator::PRIMARY);
|
||||
* . // result would be Collator::EQUAL ("abc" == "ABC")
|
||||
* . // (no primary difference between "abc" and "ABC")
|
||||
* . Collator::EComparisonResult result = myCollation->compare("abc", "ABC");
|
||||
* . myCollation->setStrength(Collator::TERTIARY);
|
||||
* . // result would be Collator::LESS (abc" <<< "ABC")
|
||||
* . // (with tertiary difference between "abc" and "ABC")
|
||||
* . Collator::EComparisonResult result = myCollation->compare("abc", "ABC");
|
||||
* </pre>
|
||||
* @param source the source string to be compared with.
|
||||
* @param target the string that is to be compared with the source string.
|
||||
* @return Returns a byte value. GREATER if source is greater
|
||||
* than target; EQUAL if source is equal to target; LESS if source is less
|
||||
* than target
|
||||
**/
|
||||
virtual EComparisonResult compare( const UnicodeString& source,
|
||||
const UnicodeString& target) const = 0;
|
||||
/**
|
||||
* Does the same thing as compare but limits the comparison to a specified length
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . Collator *myCollation = Collator::createInstance(Locale::US, status);
|
||||
* . if (FAILURE(status)) return;
|
||||
* . myCollation->setStrength(Collator::PRIMARY);
|
||||
* . // result would be Collator::EQUAL ("abc" == "ABC")
|
||||
* . // (no primary difference between "abc" and "ABC")
|
||||
* . Collator::EComparisonResult result = myCollation->compare("abc", "ABC",3);
|
||||
* . myCollation->setStrength(Collator::TERTIARY);
|
||||
* . // result would be Collator::LESS (abc" <<< "ABC")
|
||||
* . // (with tertiary difference between "abc" and "ABC")
|
||||
* . Collator::EComparisonResult result = myCollation->compare("abc", "ABC",3);
|
||||
* </pre>
|
||||
* @param source the source string to be compared with.
|
||||
* @param target the string that is to be compared with the source string.
|
||||
* @param length the length the comparison is limitted to
|
||||
* @return Returns a byte value. GREATER if source (up to the specified length) is greater
|
||||
* than target; EQUAL if source (up to specified length) is equal to target; LESS if source
|
||||
* (up to the specified length) is less than target.
|
||||
**/
|
||||
|
||||
virtual EComparisonResult compare( const UnicodeString& source,
|
||||
const UnicodeString& target,
|
||||
t_int32 length) const = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
/** Transforms the string into a series of characters that can be compared
|
||||
* with CollationKey::compareTo. It is not possible to restore the original
|
||||
* string from the chars in the sort key. The generated sort key handles
|
||||
* only a limited number of ignorable characters.
|
||||
* <p>Use CollationKey::equals or CollationKey::compare to compare the
|
||||
* generated sort keys.
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . Collator *myCollation = Collator::createInstance(Locale::US, status);
|
||||
* . if (FAILURE(status)) return;
|
||||
* . myCollation->setStrength(Collator::PRIMARY);
|
||||
* . ErrorCode key1Status, key2Status;
|
||||
* . CollationKey CollationKey1
|
||||
* . CollationKey1 = myCollation->getCollationKey("abc", CollationKey1, key1Status);
|
||||
* . CollationKey CollationKey2
|
||||
* . CollationKey2 = myCollation->getCollationKey("ABC", CollationKey2, key2Status);
|
||||
* . if (FAILURE(key1Status) || FAILURE(key2Status)) { delete myCollation; return; }
|
||||
* . // Use CollationKey::compare() to compare the sort keys
|
||||
* . // result would be 0 (CollationKey1 == CollationKey2)
|
||||
* . int result = CollationKey1.compare(CollationKey2);
|
||||
* . myCollation->setStrength(Collator::TERTIARY);
|
||||
* . CollationKey1 = myCollation->getCollationKey("abc", CollationKey1, key1Status);
|
||||
* . CollationKey2 = myCollation->getCollationKey("ABC", CollationKey2, key2Status);
|
||||
* . if (FAILURE(key1Status) || FAILURE(key2Status)) { delete myCollation; return; }
|
||||
* . // Use CollationKey::compareTo to compare the collation keys
|
||||
* . // result would be -1 (CollationKey1 < CollationKey2)
|
||||
* . result = CollationKey1.compareTo(CollationKey2);
|
||||
* . delete myCollation;
|
||||
* </pre>
|
||||
* <p>If the source string is null, a null collation key will be returned.
|
||||
* @param source the source string to be transformed into a sort key.
|
||||
* @param key the collation key to be filled in
|
||||
* @return the collation key of the string based on the collation rules.
|
||||
* @see CollationKey#compare
|
||||
*/
|
||||
virtual CollationKey& getCollationKey( const UnicodeString& source,
|
||||
CollationKey& key,
|
||||
ErrorCode& status) const = 0;
|
||||
/**
|
||||
* Transforms the string into a unsigned short array that can be compared,
|
||||
* the caller owns the returned array.
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . Collator *myCollation = Collator::createInstance(Locale::US, status);
|
||||
* . if (FAILURE(status)) return;
|
||||
* . myCollation->setStrength(Collator::PRIMARY);
|
||||
* . ErrorCode key1Status, key2Status;
|
||||
* . t_uint16 *array1 = 0;
|
||||
* . t_uint16 *array2 = 0;
|
||||
* . t_int32 array1Count, array2Count;
|
||||
* . array1 = myCollation->getCollationKey("abc", array1Count, key1Status);
|
||||
* . array2 = myCollation->getCollationKey("ABC", array2Count, key2Status);
|
||||
* . if (FAILURE(key1Status) || FAILURE(key2Status)) { delete myCollation; return; }
|
||||
* . // Use a loop to compare the two arrays
|
||||
* . delete array1;
|
||||
* . delete array2;
|
||||
* . delete myCollation;
|
||||
* </pre>
|
||||
* <p>If the source string is null, a null collation key will be returned.
|
||||
* @param source the source string to be transformed into a sort key.
|
||||
* @param count returns the number of elements in the returned array.
|
||||
* @return the collation key value array of the string based on the collation rules.
|
||||
* @see CollationKey#compare
|
||||
*/
|
||||
virtual UniChar* createCollationKeyValues( const UnicodeString& source,
|
||||
t_int32& count,
|
||||
ErrorCode& status) const = 0;
|
||||
|
||||
/**
|
||||
* The following method is obsolete in our current APIs. Some methods
|
||||
* were renamed in JDK 1.1. The older versions of the methods will be kept
|
||||
* around for compatibility but will be made obsolete in the future.
|
||||
*/
|
||||
|
||||
virtual SortKey& getSortKey( const UnicodeString& source,
|
||||
SortKey& key,
|
||||
ErrorCode& status) const;
|
||||
/**
|
||||
* Generates the hash code for the collation object
|
||||
*/
|
||||
virtual t_int32 hashCode() const = 0;
|
||||
|
||||
/**
|
||||
* Convenience method for comparing two strings based on
|
||||
* the collation rules.
|
||||
* @param source the source string to be compared with.
|
||||
* @param target the target string to be compared with.
|
||||
* @return true if the first string is greater than the second one,
|
||||
* according to the collation rules. false, otherwise.
|
||||
* @see Collator#compare
|
||||
*/
|
||||
t_bool greater( const UnicodeString& source,
|
||||
const UnicodeString& target) const;
|
||||
/**
|
||||
* Convenience method for comparing two strings based on the collation
|
||||
* rules.
|
||||
* @param source the source string to be compared with.
|
||||
* @param target the target string to be compared with.
|
||||
* @return true if the first string is greater than or equal to the
|
||||
* second one, according to the collation rules. false, otherwise.
|
||||
* @see Collator#compare
|
||||
*/
|
||||
t_bool greaterOrEqual( const UnicodeString& source,
|
||||
const UnicodeString& target) const;
|
||||
/**
|
||||
* Convenience method for comparing two strings based on the collation
|
||||
* rules.
|
||||
* @param source the source string to be compared with.
|
||||
* @param target the target string to be compared with.
|
||||
* @return true if the strings are equal according to the collation
|
||||
* rules. false, otherwise.
|
||||
* @see Collator#compare
|
||||
*/
|
||||
t_bool equals( const UnicodeString& source,
|
||||
const UnicodeString& target) const;
|
||||
|
||||
// getter/setter
|
||||
/**
|
||||
* Get the decomposition mode of the collator object.
|
||||
* @return the decomposition mode
|
||||
* @see Collator#setDecomposition
|
||||
*/
|
||||
EDecompositionMode getDecomposition() const;
|
||||
/**
|
||||
* Set the decomposition mode of the collator object. success is equal
|
||||
* to ILLEGAL_ARGUMENT_ERROR if error occurs.
|
||||
* @param the new decomposition mode
|
||||
* @see Collator#getDecomposition
|
||||
*/
|
||||
void setDecomposition( EDecompositionMode mode);
|
||||
/**
|
||||
* Determines the minimum strength that will be use in comparison or
|
||||
* transformation.
|
||||
* <p>E.g. with strength == SECONDARY, the tertiary difference is ignored
|
||||
* <p>E.g. with strength == PRIMARY, the secondary and tertiary difference
|
||||
* are ignored.
|
||||
* @return the current comparison level.
|
||||
* @see Collator#setStrength
|
||||
*/
|
||||
ECollationStrength getStrength() const;
|
||||
/**
|
||||
* Sets the minimum strength to be used in comparison or transformation.
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . Collator *myCollation = Collator::createInstance(Locale::US, status);
|
||||
* . if (FAILURE(status)) return;
|
||||
* . myCollation->setStrength(Collator::PRIMARY);
|
||||
* . // result will be "abc" == "ABC"
|
||||
* . // tertiary differences will be ignored
|
||||
* . Collator::ComparisonResult result = myCollation->compare("abc", "ABC");
|
||||
* </pre>
|
||||
* @see Collator#getStrength
|
||||
* @param newStrength the new comparison level.
|
||||
*/
|
||||
void setStrength( ECollationStrength newStrength);
|
||||
/**
|
||||
* Get name of the object for the desired Locale, in the desired langauge
|
||||
* @param objectLocale must be from getAvailableLocales
|
||||
* @param displayLocale specifies the desired locale for output
|
||||
* @param name the fill-in parameter of the return value
|
||||
* @return display-able name of the object for the object locale in the
|
||||
* desired language
|
||||
*/
|
||||
static UnicodeString& getDisplayName( const Locale& objectLocale,
|
||||
const Locale& displayLocale,
|
||||
UnicodeString& name) ;
|
||||
/**
|
||||
* Get name of the object for the desired Locale, in the langauge of the
|
||||
* default locale.
|
||||
* @param objectLocale must be from getAvailableLocales
|
||||
* @param name the fill-in parameter of the return value
|
||||
* @return name of the object for the desired locale in the default
|
||||
* language
|
||||
*/
|
||||
static UnicodeString& getDisplayName( const Locale& objectLocale,
|
||||
UnicodeString& name) ;
|
||||
|
||||
/**
|
||||
* Get the set of Locales for which Collations are installed
|
||||
* @param count the output parameter of number of elements in the locale list
|
||||
* @return the list of available locales which collations are installed
|
||||
*/
|
||||
static const Locale* getAvailableLocales(t_int32& count);
|
||||
|
||||
/**
|
||||
* Returns a unique class ID POLYMORPHICALLY. Pure virtual method.
|
||||
* This method is to implement a simple version of RTTI, since not all
|
||||
* C++ compilers support genuine RTTI. Polymorphic operator==() and
|
||||
* clone() methods call this method.
|
||||
*
|
||||
* Concrete subclasses of Format must implement getDynamicClassID()
|
||||
* and also a static method and data member:
|
||||
*
|
||||
* static ClassID getStaticClassID() { return (ClassID)&fgClassID; }
|
||||
* static char fgClassID;
|
||||
*
|
||||
* @return The class ID for this object. All objects of a
|
||||
* given class have the same class ID. Objects of
|
||||
* other classes have different class IDs.
|
||||
*/
|
||||
virtual ClassID getDynamicClassID() const = 0;
|
||||
|
||||
/** Netscape
|
||||
* Returns the version number for the collator
|
||||
* format is major.minor ie: 01.00
|
||||
*/
|
||||
virtual const char* getVersionNumber();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructors
|
||||
*/
|
||||
Collator();
|
||||
Collator(const Collator& other);
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
*/
|
||||
const Collator& operator=(const Collator& other);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
private:
|
||||
|
||||
ECollationStrength strength;
|
||||
EDecompositionMode decmp;
|
||||
};
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
inline t_bool
|
||||
Collator::operator==(const Collator& other) const
|
||||
{
|
||||
t_bool result;
|
||||
if (this == &other) result = TRUE;
|
||||
else result = ((strength == other.strength) && (decmp == other.decmp));
|
||||
return result;
|
||||
}
|
||||
|
||||
inline t_bool
|
||||
Collator::operator!=(const Collator& other) const
|
||||
{
|
||||
t_bool result;
|
||||
result = !(*this == other);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Collator*
|
||||
Collator::createDefault(ErrorCode& status)
|
||||
{
|
||||
return Collator::createInstance(status);
|
||||
}
|
||||
|
||||
inline Collator*
|
||||
Collator::createDefault(const Locale& loc,
|
||||
ErrorCode& status)
|
||||
{
|
||||
return Collator::createInstance(loc, status);
|
||||
}
|
||||
|
||||
inline SortKey&
|
||||
Collator::getSortKey( const UnicodeString& source,
|
||||
SortKey& key,
|
||||
ErrorCode& status) const
|
||||
{
|
||||
return (SortKey&)getCollationKey(source, (CollationKey&)key, status);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,648 @@
|
|||
/*
|
||||
********************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1997 *
|
||||
* (C) Copyright International Business Machines Corporation, 1997 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
********************************************************************************
|
||||
*
|
||||
* File DECIMFMT.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/19/97 aliu Converted from java.
|
||||
* 03/20/97 clhuang Updated per C++ implementation.
|
||||
* 04/03/97 aliu Rewrote parsing and formatting completely, and
|
||||
* cleaned up and debugged. Actually works now.
|
||||
* 04/17/97 aliu Changed DigitCount to int per code review.
|
||||
* 07/10/97 helena Made ParsePosition a class and get rid of the function
|
||||
* hiding problems.
|
||||
* 09/09/97 aliu Ported over support for exponential formats.
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _DECIMFMT
|
||||
#define _DECIMFMT
|
||||
|
||||
#include "ptypes.h"
|
||||
#include "numfmt.h"
|
||||
#include "locid.h"
|
||||
class DecimalFormatSymbols;
|
||||
class DigitList;
|
||||
|
||||
/**
|
||||
* Concrete class for formatting decimal numbers, allowing a variety
|
||||
* of parameters, and localization to Western, Arabic, or Indic numbers.
|
||||
* <P>
|
||||
* Normally, you get the proper NumberFormat for a specific locale
|
||||
* (including the default locale) using the NumberFormat factory methods,
|
||||
* rather than constructing a DecimalNumberFormat directly.
|
||||
* <P>
|
||||
* Either the prefixes or the suffixes must be different for the parse
|
||||
* to distinguish positive from negative. Parsing will be unreliable
|
||||
* if the digits, thousands or decimal separators are the same, or if
|
||||
* any of them occur in the prefixes or suffixes.
|
||||
* <P>
|
||||
* [Special cases:]
|
||||
* <P>
|
||||
* NaN is formatted as a single character, typically \\uFFFD.
|
||||
* <P>
|
||||
* +/-Infinity is formatted as a single character, typically \\u221E,
|
||||
* plus the positive and negative pre/suffixes.
|
||||
* <P>
|
||||
* Note: this class is designed for common users; for very large or small
|
||||
* numbers, use a format that can express exponential values.
|
||||
* <P>
|
||||
* [Example:]
|
||||
* <pre>
|
||||
* . // normally we would have a GUI with a menu for this
|
||||
* . long count;
|
||||
* . Locale* locales = NumberFormat::getAvailableLocales(count);
|
||||
*
|
||||
* . double myNumber = -1234.56;
|
||||
* . NumberFormat* form;
|
||||
*
|
||||
* . // just for fun, we print out a number with the locale number, currency
|
||||
* . // and percent format for each locale we can.
|
||||
* . for (int j = 0; j < 3; ++j) {
|
||||
* . cout << "FORMAT" << endl;
|
||||
* . for (int i = 0; i < count; ++i) {
|
||||
* . if (locales[i]->getCountry().length() == 0) {
|
||||
* . // skip language-only
|
||||
* . continue;
|
||||
* . }
|
||||
* . cout << locales[i]->getDisplayName();
|
||||
* . switch (j) {
|
||||
* . default:
|
||||
* . form = NumberFormat::getInstance(*locales[i]); break;
|
||||
* . case 1:
|
||||
* . form = NumberFormat::getDefaultCurrency(*locales[i]); break;
|
||||
* . case 0:
|
||||
* . form = NumberFormat::getDefaultPercent(*locales[i]); break;
|
||||
* . }
|
||||
* . UnicodeString str;
|
||||
* . ErrorCode status;
|
||||
* . UnicodeString pattern;
|
||||
* . if (form->getDynamicClassID() == DecimalFormat::getStaticClassID())
|
||||
* . ((DecimalFormat*)form)->toPattern(pattern);
|
||||
* . cout << ": " << pattern
|
||||
* . << " -> " << form->format(myNumber, str);
|
||||
* . cout << " -> " << form->parse(form->format(myNumber, str), status)
|
||||
* . << endl;
|
||||
* . }
|
||||
* . }
|
||||
* </pre>
|
||||
* [The following shows the structure of the pattern.]
|
||||
* <pre>
|
||||
* . pattern := subpattern{;subpattern}
|
||||
* . subpattern := {prefix}integer{.fraction}{suffix}
|
||||
* .
|
||||
* . prefix := '\\u0000'..'\\uFFFD' - specialCharacters
|
||||
* . suffix := '\\u0000'..'\\uFFFD' - specialCharacters
|
||||
* . integer := '#'* '0'* '0'
|
||||
* . fraction := '0'* '#'*
|
||||
*
|
||||
* Notation:
|
||||
* . X* 0 or more instances of X
|
||||
* . (X | Y) either X or Y.
|
||||
* . X..Y any character from X up to Y, inclusive.
|
||||
* . S - T characters in S, except those in T
|
||||
* </pre>
|
||||
* The first subpattern is for positive numbers. The second (optional)
|
||||
* subpattern is used for negative numbers. (In both cases, ',' can
|
||||
* occur inside the integer portion--it is just too messy to indicate
|
||||
* in BNF.) For the second subpattern, only the PREFIX and SUFFIX are
|
||||
* noted; other attributes are taken only from the first subpattern.
|
||||
* <P>
|
||||
* Here are the special characters used in the parts of the
|
||||
* subpattern, with notes on their usage.
|
||||
* <pre>
|
||||
* . Symbol Meaning
|
||||
* . 0 a digit, showing up a zero if it is zero
|
||||
* . # a digit, supressed if zero
|
||||
* . . placeholder for decimal separator
|
||||
* . , placeholder for grouping separator
|
||||
* . ; separates postive from negative formats
|
||||
* . - default negative prefix
|
||||
* . % divide by 100 and show as percentage
|
||||
* . X any other characters can be used in the prefix or suffix
|
||||
* . ' used to quote special characters in a prefix or suffix
|
||||
* </pre>
|
||||
* [Notes]
|
||||
* <P>
|
||||
* If there is no explicit negative subpattern, - is prefixed to the
|
||||
* positive form. That is, "0.00" alone is equivalent to "0.00;-0.00".
|
||||
* <P>
|
||||
* Illegal formats, such as "#.#.#" in the same format, will cause a
|
||||
* failing ErrorCode to be returned.
|
||||
* <P>
|
||||
* The grouping separator is commonly used for thousands, but in some
|
||||
* countries for ten-thousands. The interval is a constant number of
|
||||
* digits between the grouping characters, such as 100,000,000 or 1,0000,0000.
|
||||
* If you supply a pattern with multiple grouping characters, the interval
|
||||
* between the last one and the end of the integer is the one that is
|
||||
* used. So "#,##,###,####" == "######,####" == "##,####,####".
|
||||
* <P>
|
||||
* This class only handles localized digits where the 10 digits are
|
||||
* contiguous in Unicode, from 0 to 9. Other digits sets (such as
|
||||
* superscripts) would need a different subclass.
|
||||
*/
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
class T_FORMAT_API DecimalFormat: public NumberFormat {
|
||||
public:
|
||||
/**
|
||||
* Create a DecimalFormat using the default pattern and symbols
|
||||
* for the default locale. This is a convenient way to obtain a
|
||||
* DecimalFormat when internationalization is not the main concern.
|
||||
* <P>
|
||||
* To obtain standard formats for a given locale, use the factory methods
|
||||
* on NumberFormat such as getNumberInstance. These factories will
|
||||
* return the most appropriate sub-class of NumberFormat for a given
|
||||
* locale.
|
||||
* @param status Output param set to success/failure code. If the
|
||||
* pattern is invalid this will be set to a failure code.
|
||||
*/
|
||||
DecimalFormat(ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create a DecimalFormat from the given pattern and the symbols
|
||||
* for the default locale. This is a convenient way to obtain a
|
||||
* DecimalFormat when internationalization is not the main concern.
|
||||
* <P>
|
||||
* To obtain standard formats for a given locale, use the factory methods
|
||||
* on NumberFormat such as getNumberInstance. These factories will
|
||||
* return the most appropriate sub-class of NumberFormat for a given
|
||||
* locale.
|
||||
* @param pattern A non-localized pattern string.
|
||||
* @param status Output param set to success/failure code. If the
|
||||
* pattern is invalid this will be set to a failure code.
|
||||
*/
|
||||
DecimalFormat(const UnicodeString& pattern,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create a DecimalFormat from the given pattern and symbols.
|
||||
* Use this constructor when you need to completely customize the
|
||||
* behavior of the format.
|
||||
* <P>
|
||||
* To obtain standard formats for a given
|
||||
* locale, use the factory methods on NumberFormat such as
|
||||
* getInstance or getCurrencyInstance. If you need only minor adjustments
|
||||
* to a standard format, you can modify the format returned by
|
||||
* a NumberFormat factory method.
|
||||
*
|
||||
* @param pattern a non-localized pattern string
|
||||
* @param symbolsToAdopt the set of symbols to be used. The caller should not
|
||||
* delete this object after making this call.
|
||||
* @param status Output param set to success/failure code. If the
|
||||
* pattern is invalid this will be set to a failure code.
|
||||
*/
|
||||
DecimalFormat( const UnicodeString& pattern,
|
||||
DecimalFormatSymbols* symbolsToAdopt,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Create a DecimalFormat from the given pattern and symbols.
|
||||
* Use this constructor when you need to completely customize the
|
||||
* behavior of the format.
|
||||
* <P>
|
||||
* To obtain standard formats for a given
|
||||
* locale, use the factory methods on NumberFormat such as
|
||||
* getInstance or getCurrencyInstance. If you need only minor adjustments
|
||||
* to a standard format, you can modify the format returned by
|
||||
* a NumberFormat factory method.
|
||||
*
|
||||
* @param pattern a non-localized pattern string
|
||||
* @param symbols the set of symbols to be used
|
||||
* @param status Output param set to success/failure code. If the
|
||||
* pattern is invalid this will be set to a failure code.
|
||||
*/
|
||||
DecimalFormat( const UnicodeString& pattern,
|
||||
const DecimalFormatSymbols& symbols,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
DecimalFormat(const DecimalFormat& source);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*/
|
||||
DecimalFormat& operator=(const DecimalFormat& rhs);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~DecimalFormat();
|
||||
|
||||
/**
|
||||
* Clone this Format object polymorphically. The caller owns the
|
||||
* result and should delete it when done.
|
||||
*/
|
||||
virtual Format* clone() const;
|
||||
|
||||
/**
|
||||
* Return true if the given Format objects are semantically equal.
|
||||
* Objects of different subclasses are considered unequal.
|
||||
*/
|
||||
virtual t_bool operator==(const Format& other) const;
|
||||
|
||||
/**
|
||||
* Format a double or long number using base-10 representation.
|
||||
*
|
||||
* @param number The value to be formatted.
|
||||
* @param toAppendTo The string to append the formatted string to.
|
||||
* This is an output parameter.
|
||||
* @param pos On input: an alignment field, if desired.
|
||||
* On output: the offsets of the alignment field.
|
||||
* @return A reference to 'toAppendTo'.
|
||||
*/
|
||||
virtual UnicodeString& format(double number,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos) const;
|
||||
virtual UnicodeString& format(long number,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos) const;
|
||||
virtual UnicodeString& format(const Formattable& obj,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos,
|
||||
ErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Parse the given string using this object's choices. The method
|
||||
* does string comparisons to try to find an optimal match.
|
||||
* If no object can be parsed, index is unchanged, and NULL is
|
||||
* returned.
|
||||
*
|
||||
* @param text The text to be parsed.
|
||||
* @param result Formattable to be set to the parse result.
|
||||
* If parse fails, return contents are undefined.
|
||||
* @param parsePosition The position to start parsing at on input.
|
||||
* On output, moved to after the last successfully
|
||||
* parse character. On parse failure, does not change.
|
||||
*/
|
||||
virtual void parse(const UnicodeString& text,
|
||||
Formattable& result,
|
||||
ParsePosition& parsePosition) const;
|
||||
|
||||
// Declare here again to get rid of function hiding problems.
|
||||
virtual void parse(const UnicodeString& text,
|
||||
Formattable& result,
|
||||
ErrorCode& error) const;
|
||||
|
||||
/**
|
||||
* Returns the decimal format symbols, which is generally not changed
|
||||
* by the programmer or user.
|
||||
* @return desired DecimalFormatSymbols
|
||||
* @see DecimalFormatSymbols
|
||||
*/
|
||||
virtual const DecimalFormatSymbols* getDecimalFormatSymbols() const;
|
||||
|
||||
/**
|
||||
* Sets the decimal format symbols, which is generally not changed
|
||||
* by the programmer or user.
|
||||
* @param symbolsToAdopt DecimalFormatSymbols to be adopted.
|
||||
*/
|
||||
virtual void adoptDecimalFormatSymbols(DecimalFormatSymbols* symbolsToAdopt);
|
||||
|
||||
/**
|
||||
* Sets the decimal format symbols, which is generally not changed
|
||||
* by the programmer or user.
|
||||
* @param symbols DecimalFormatSymbols.
|
||||
*/
|
||||
virtual void setDecimalFormatSymbols(const DecimalFormatSymbols& symbols);
|
||||
|
||||
|
||||
/**
|
||||
* Get the positive prefix.
|
||||
*
|
||||
* Examples: +123, $123, sFr123
|
||||
*/
|
||||
UnicodeString& getPositivePrefix(UnicodeString& result) const;
|
||||
|
||||
/**
|
||||
* Set the positive prefix.
|
||||
*
|
||||
* Examples: +123, $123, sFr123
|
||||
*/
|
||||
virtual void setPositivePrefix(const UnicodeString& newValue);
|
||||
|
||||
/**
|
||||
* Get the negative prefix.
|
||||
*
|
||||
* Examples: -123, ($123) (with negative suffix), sFr-123
|
||||
*/
|
||||
UnicodeString& getNegativePrefix(UnicodeString& result) const;
|
||||
/**
|
||||
* Set the negative prefix.
|
||||
*
|
||||
* Examples: -123, ($123) (with negative suffix), sFr-123
|
||||
*/
|
||||
virtual void setNegativePrefix(const UnicodeString& newValue);
|
||||
|
||||
/**
|
||||
* Get the positive suffix.
|
||||
*
|
||||
* Example: 123%
|
||||
*/
|
||||
UnicodeString& getPositiveSuffix(UnicodeString& result) const;
|
||||
|
||||
/**
|
||||
* Set the positive suffix.
|
||||
*
|
||||
* Example: 123%
|
||||
*/
|
||||
virtual void setPositiveSuffix(const UnicodeString& newValue);
|
||||
|
||||
/**
|
||||
* Get the negative suffix.
|
||||
*
|
||||
* Examples: -123%, ($123) (with positive suffixes)
|
||||
*/
|
||||
UnicodeString& getNegativeSuffix(UnicodeString& result) const;
|
||||
|
||||
/**
|
||||
* Set the positive suffix.
|
||||
*
|
||||
* Examples: 123%
|
||||
*/
|
||||
virtual void setNegativeSuffix(const UnicodeString& newValue);
|
||||
|
||||
/**
|
||||
* Get the multiplier for use in percent, permill, etc.
|
||||
* For a percentage, set the suffixes to have "%" and the multiplier to be 100.
|
||||
* (For Arabic, use arabic percent symbol).
|
||||
* For a permill, set the suffixes to have "\u2031" and the multiplier to be 1000.
|
||||
*
|
||||
* Examples: with 100, 1.23 -> "123", and "123" -> 1.23
|
||||
*/
|
||||
t_int32 getMultiplier() const;
|
||||
|
||||
/**
|
||||
* Set the multiplier for use in percent, permill, etc.
|
||||
* For a percentage, set the suffixes to have "%" and the multiplier to be 100.
|
||||
* (For Arabic, use arabic percent symbol).
|
||||
* For a permill, set the suffixes to have "\u2031" and the multiplier to be 1000.
|
||||
*
|
||||
* Examples: with 100, 1.23 -> "123", and "123" -> 1.23
|
||||
*/
|
||||
virtual void setMultiplier(t_int32 newValue);
|
||||
|
||||
/**
|
||||
* Return the grouping size. Grouping size is the number of digits between
|
||||
* grouping separators in the integer portion of a number. For example,
|
||||
* in the number "123,456.78", the grouping size is 3.
|
||||
* @see setGroupingSize
|
||||
* @see NumberFormat::isGroupingUsed
|
||||
* @see DecimalFormatSymbols::getGroupingSeparator
|
||||
*/
|
||||
int getGroupingSize() const;
|
||||
|
||||
/**
|
||||
* Set the grouping size. Grouping size is the number of digits between
|
||||
* grouping separators in the integer portion of a number. For example,
|
||||
* in the number "123,456.78", the grouping size is 3.
|
||||
* @see getGroupingSize
|
||||
* @see NumberFormat::setGroupingUsed
|
||||
* @see DecimalFormatSymbols::setGroupingSeparator
|
||||
*/
|
||||
virtual void setGroupingSize(int newValue);
|
||||
|
||||
/**
|
||||
* Allows you to get the behavior of the decimal separator with integers.
|
||||
* (The decimal separator will always appear with decimals.)
|
||||
*
|
||||
* Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
|
||||
*/
|
||||
t_bool isDecimalSeparatorAlwaysShown() const;
|
||||
|
||||
/**
|
||||
* Allows you to set the behavior of the decimal separator with integers.
|
||||
* (The decimal separator will always appear with decimals.)
|
||||
*
|
||||
* Example: Decimal ON: 12345 -> 12345.; OFF: 12345 -> 12345
|
||||
*/
|
||||
virtual void setDecimalSeparatorAlwaysShown(t_bool newValue);
|
||||
|
||||
/**
|
||||
* Synthesizes a pattern string that represents the current state
|
||||
* of this Format object.
|
||||
* @see applyPattern
|
||||
*/
|
||||
virtual UnicodeString& toPattern(UnicodeString& result) const;
|
||||
|
||||
/**
|
||||
* Synthesizes a localized pattern string that represents the current
|
||||
* state of this Format object.
|
||||
*
|
||||
* @see applyPattern
|
||||
*/
|
||||
virtual UnicodeString& toLocalizedPattern(UnicodeString& result) const;
|
||||
|
||||
/**
|
||||
* Apply the given pattern to this Format object. A pattern is a
|
||||
* short-hand specification for the various formatting properties.
|
||||
* These properties can also be changed individually through the
|
||||
* various setter methods.
|
||||
* <P>
|
||||
* There is no limit to integer digits are set
|
||||
* by this routine, since that is the typical end-user desire;
|
||||
* use setMaximumInteger if you want to set a real value.
|
||||
* For negative numbers, use a second pattern, separated by a semicolon
|
||||
* <pre>
|
||||
* . Example "#,#00.0#" -> 1,234.56
|
||||
* </pre>
|
||||
* This means a minimum of 2 integer digits, 1 fraction digit, and
|
||||
* a maximum of 2 fraction digits.
|
||||
* <pre>
|
||||
* . Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
|
||||
* </pre>
|
||||
* In negative patterns, the minimum and maximum counts are ignored;
|
||||
* these are presumed to be set in the positive pattern.
|
||||
*
|
||||
* @param pattern The pattern to be applied.
|
||||
* @param status Output param set to success/failure code on
|
||||
* exit. If the pattern is invalid, this will be
|
||||
* set to a failure result.
|
||||
*/
|
||||
virtual void applyPattern(const UnicodeString& pattern,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Apply the given pattern to this Format object. The pattern
|
||||
* is assumed to be in a localized notation. A pattern is a
|
||||
* short-hand specification for the various formatting properties.
|
||||
* These properties can also be changed individually through the
|
||||
* various setter methods.
|
||||
* <P>
|
||||
* There is no limit to integer digits are set
|
||||
* by this routine, since that is the typical end-user desire;
|
||||
* use setMaximumInteger if you want to set a real value.
|
||||
* For negative numbers, use a second pattern, separated by a semicolon
|
||||
* <pre>
|
||||
* . Example "#,#00.0#" -> 1,234.56
|
||||
* </pre>
|
||||
* This means a minimum of 2 integer digits, 1 fraction digit, and
|
||||
* a maximum of 2 fraction digits.
|
||||
*
|
||||
* Example: "#,#00.0#;(#,#00.0#)" for negatives in parantheses.
|
||||
*
|
||||
* In negative patterns, the minimum and maximum counts are ignored;
|
||||
* these are presumed to be set in the positive pattern.
|
||||
*
|
||||
* @param pattern The localized pattern to be applied.
|
||||
* @param status Output param set to success/failure code on
|
||||
* exit. If the pattern is invalid, this will be
|
||||
* set to a failure result.
|
||||
*/
|
||||
virtual void applyLocalizedPattern(const UnicodeString& pattern,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* The resource tags we use to retrieve decimal format data from
|
||||
* locale resource bundles.
|
||||
*/
|
||||
static const UnicodeString kNumberPatterns;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Return the class ID for this class. This is useful only for
|
||||
* comparing to a return value from getDynamicClassID(). For example:
|
||||
* <pre>
|
||||
* . Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* . if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* . Derived::getStaticClassID()) ...
|
||||
* </pre>
|
||||
* @return The class ID for all objects of this class.
|
||||
*/
|
||||
static ClassID getStaticClassID() { return (ClassID)&fgClassID; }
|
||||
|
||||
/**
|
||||
* Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
|
||||
* This method is to implement a simple version of RTTI, since not all
|
||||
* C++ compilers support genuine RTTI. Polymorphic operator==() and
|
||||
* clone() methods call this method.
|
||||
*
|
||||
* @return The class ID for this object. All objects of a
|
||||
* given class have the same class ID. Objects of
|
||||
* other classes have different class IDs.
|
||||
*/
|
||||
virtual ClassID getDynamicClassID() const { return getStaticClassID(); }
|
||||
|
||||
private:
|
||||
static char fgClassID;
|
||||
|
||||
/**
|
||||
* Do real work of constructing a new DecimalFormat.
|
||||
*/
|
||||
void construct(ErrorCode& status,
|
||||
const UnicodeString* pattern = 0,
|
||||
DecimalFormatSymbols* symbolsToAdopt = 0,
|
||||
const Locale& locale = Locale::getDefault());
|
||||
|
||||
/**
|
||||
* Does the real work of generating a pattern.
|
||||
*/
|
||||
UnicodeString& toPattern(UnicodeString& result, t_bool localized) const;
|
||||
|
||||
/**
|
||||
* Does the real work of applying a pattern.
|
||||
* @param pattern The pattern to be applied.
|
||||
* @param localized If true, the pattern is localized; else false.
|
||||
* @param status Output param set to success/failure code on
|
||||
* exit. If the pattern is invalid, this will be
|
||||
* set to a failure result.
|
||||
*/
|
||||
void applyPattern(const UnicodeString& pattern,
|
||||
t_bool localized,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Do the work of formatting a number, either a double or a long.
|
||||
*/
|
||||
UnicodeString& subformat(UnicodeString& result,
|
||||
FieldPosition& fieldPosition,
|
||||
t_bool isNegative,
|
||||
t_bool isInteger) const;
|
||||
|
||||
static const int STATUS_INFINITE;
|
||||
static const int STATUS_POSITIVE;
|
||||
static const int STATUS_LENGTH;
|
||||
|
||||
/**
|
||||
* Parse the given text into a number. The text is parsed beginning at
|
||||
* parsePosition, until an unparseable character is seen.
|
||||
* @param text The string to parse.
|
||||
* @param parsePosition The position at which to being parsing. Upon
|
||||
* return, the first unparseable character.
|
||||
* @param digits The DigitList to set to the parsed value.
|
||||
* @param isExponent If true, parse an exponent. This means no
|
||||
* infinite values and integer only.
|
||||
* @param status Upon return contains boolean status flags indicating
|
||||
* whether the value was infinite and whether it was positive.
|
||||
*/
|
||||
t_bool subparse(const UnicodeString& text, ParsePosition& parsePosition,
|
||||
DigitList& digits, t_bool isExponent,
|
||||
t_bool* status) const;
|
||||
|
||||
/**
|
||||
* Constants.
|
||||
*/
|
||||
static const t_int8 kMaxDigit; // The largest digit, in this case 9
|
||||
|
||||
/*transient*/ DigitList* digitList;
|
||||
|
||||
UnicodeString fPositivePrefix;
|
||||
UnicodeString fPositiveSuffix;
|
||||
UnicodeString fNegativePrefix;
|
||||
UnicodeString fNegativeSuffix;
|
||||
t_int32 fMultiplier;
|
||||
int fGroupingSize;
|
||||
t_bool fDecimalSeparatorAlwaysShown;
|
||||
/*transient*/ t_bool isCurrencyFormat;
|
||||
DecimalFormatSymbols* fSymbols;
|
||||
|
||||
t_bool useExponentialNotation;
|
||||
t_int8 minExponentDigits;
|
||||
|
||||
// Constants for characters used in programmatic (unlocalized) patterns.
|
||||
static const UniChar PATTERN_ZERO_DIGIT;
|
||||
static const UniChar PATTERN_GROUPING_SEPARATOR;
|
||||
static const UniChar PATTERN_DECIMAL_SEPARATOR;
|
||||
static const UniChar PATTERN_PER_MILLE;
|
||||
static const UniChar PATTERN_PERCENT;
|
||||
static const UniChar PATTERN_DIGIT;
|
||||
static const UniChar PATTERN_SEPARATOR;
|
||||
static const UniChar PATTERN_EXPONENT;
|
||||
|
||||
/**
|
||||
* The CURRENCY_SIGN is the standard Unicode symbol for currency. It
|
||||
* is used in patterns and substitued with either the currency symbol,
|
||||
* or if it is doubled, with the international currency symbol. If the
|
||||
* CURRENCY_SIGN is seen in a pattern, then the decimal separator is
|
||||
* replaced with the monetary decimal separator.
|
||||
*/
|
||||
static const UniChar CURRENCY_SIGN;
|
||||
|
||||
static const UniChar QUOTE;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
#endif // _DECIMFMT
|
||||
//eof
|
|
@ -0,0 +1,382 @@
|
|||
/*
|
||||
********************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1997 *
|
||||
* (C) Copyright International Business Machines Corporation, 1997 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
********************************************************************************
|
||||
*
|
||||
* File DTFMTSYM.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/19/97 aliu Converted from java.
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _DTFMTSYM
|
||||
#define _DTFMTSYM
|
||||
|
||||
#include "ptypes.h"
|
||||
#include "locid.h"
|
||||
|
||||
/**
|
||||
* DateFormatSymbols is a public class for encapsulating localizable date-time
|
||||
* formatting data -- including timezone data. DateFormatSymbols is used by
|
||||
* DateFormat and SimpleDateFormat.
|
||||
* <P>
|
||||
* Rather than first creating a DateFormatSymbols to get a date-time formatter
|
||||
* by using a SimpleDateFormat constructor, clients are encouraged to create a
|
||||
* date-time formatter using the getTimeInstance(), getDateInstance(), or
|
||||
* getDateTimeInstance() method in DateFormat. Each of these methods can return a
|
||||
* date/time formatter initialized with a default format pattern along with the
|
||||
* date-time formatting data for a given or default locale. After a formatter is
|
||||
* created, clients may modify the format pattern using the setPattern function
|
||||
* as so desired. For more information on using these formatter factory
|
||||
* functions, see DateFormat.
|
||||
* <P>
|
||||
* If clients decide to create a date-time formatter with a particular format
|
||||
* pattern and locale, they can do so with new SimpleDateFormat(aPattern,
|
||||
* new DateFormatSymbols(aLocale)). This will load the appropriate date-time
|
||||
* formatting data from the locale.
|
||||
* <P>
|
||||
* DateFormatSymbols objects are clonable. When clients obtain a
|
||||
* DateFormatSymbols object, they can feel free to modify the date-time
|
||||
* formatting data as necessary. For instance, clients can
|
||||
* replace the localized date-time format pattern characters with the ones that
|
||||
* they feel easy to remember. Or they can change the representative cities
|
||||
* originally picked by default to using their favorite ones.
|
||||
* <P>
|
||||
* New DateFormatSymbols sub-classes may be added to support SimpleDateFormat
|
||||
* for date-time formatting for additional locales.
|
||||
*/
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
class T_FORMAT_API DateFormatSymbols {
|
||||
public:
|
||||
/**
|
||||
* Construct a DateFormatSymbols object by loading format data from
|
||||
* resources for the default locale.
|
||||
* <P>
|
||||
* NOTE: This constructor will never fail; if it cannot get resource
|
||||
* data for the default locale, it will return a last-resort object
|
||||
* based on hard-coded strings.
|
||||
*
|
||||
* @param status Output param set to success of failure. Failure
|
||||
* results if the resources for the default cannot be
|
||||
* found or cannot be loaded
|
||||
*/
|
||||
DateFormatSymbols(ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Construct a DateFormatSymbols object by loading format data from
|
||||
* resources for the given locale.
|
||||
*
|
||||
* @param locale Locale to load format data from.
|
||||
* @param status Output param set to success of failure. Failure
|
||||
* results if the resources for the locale cannot be
|
||||
* found or cannot be loaded
|
||||
*/
|
||||
DateFormatSymbols(const Locale& locale,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
DateFormatSymbols(const DateFormatSymbols&);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*/
|
||||
DateFormatSymbols& operator=(const DateFormatSymbols&);
|
||||
|
||||
/**
|
||||
* Destructor. This is nonvirtual because this class is not designed to be
|
||||
* subclassed.
|
||||
*/
|
||||
~DateFormatSymbols();
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically equal to this one.
|
||||
*/
|
||||
t_bool operator==(const DateFormatSymbols& other) const;
|
||||
|
||||
/**
|
||||
* Return true if another object is semantically unequal to this one.
|
||||
*/
|
||||
t_bool operator!=(const DateFormatSymbols& other) const { return !operator==(other); }
|
||||
|
||||
/**
|
||||
* Gets era strings. For example: "AD" and "BC".
|
||||
* @return the era strings.
|
||||
*/
|
||||
const UnicodeString* getEras(t_int32& count) const;
|
||||
|
||||
/**
|
||||
* Sets era strings. For example: "AD" and "BC".
|
||||
* @param eras Array of era strings (DateFormatSymbols retains ownership.)
|
||||
* @param count Filled in with length of the array.
|
||||
*/
|
||||
void setEras(const UnicodeString* eras, t_int32 count);
|
||||
|
||||
/**
|
||||
* Gets month strings. For example: "January", "February", etc.
|
||||
* @param count Filled in with length of the array.
|
||||
* @return the month strings. (DateFormatSymbols retains ownership.)
|
||||
*/
|
||||
const UnicodeString* getMonths(t_int32& count) const;
|
||||
|
||||
/**
|
||||
* Sets month strings. For example: "January", "February", etc.
|
||||
* @param newMonths the new month strings. (not adopted; caller retains ownership)
|
||||
*/
|
||||
void setMonths(const UnicodeString* months, t_int32 count);
|
||||
|
||||
/**
|
||||
* Gets short month strings. For example: "Jan", "Feb", etc.
|
||||
* @return the short month strings. (DateFormatSymbols retains ownership.)
|
||||
*/
|
||||
const UnicodeString* getShortMonths(t_int32& count) const;
|
||||
|
||||
/**
|
||||
* Sets short month strings. For example: "Jan", "Feb", etc.
|
||||
* @param newShortMonths the new short month strings. (not adopted; caller retains ownership)
|
||||
*/
|
||||
void setShortMonths(const UnicodeString* shortMonths, t_int32 count);
|
||||
|
||||
/**
|
||||
* Gets weekday strings. For example: "Sunday", "Monday", etc.
|
||||
* @return the weekday strings. (DateFormatSymbols retains ownership.)
|
||||
*/
|
||||
const UnicodeString* getWeekdays(t_int32& count) const;
|
||||
|
||||
/**
|
||||
* Sets weekday strings. For example: "Sunday", "Monday", etc.
|
||||
* @param newWeekdays the new weekday strings. (not adopted; caller retains ownership)
|
||||
*/
|
||||
void setWeekdays(const UnicodeString* weekdays, t_int32 count);
|
||||
|
||||
/**
|
||||
* Gets short weekday strings. For example: "Sun", "Mon", etc.
|
||||
* @return the short weekday strings. (DateFormatSymbols retains ownership.)
|
||||
*/
|
||||
const UnicodeString* getShortWeekdays(t_int32& count) const;
|
||||
|
||||
/**
|
||||
* Sets short weekday strings. For example: "Sun", "Mon", etc.
|
||||
* @param newShortWeekdays the new short weekday strings. (not adopted; caller retains ownership)
|
||||
*/
|
||||
void setShortWeekdays(const UnicodeString* shortWeekdays, t_int32 count);
|
||||
|
||||
/**
|
||||
* Gets AM/PM strings. For example: "AM" and "PM".
|
||||
* @return the weekday strings. (DateFormatSymbols retains ownership.)
|
||||
*/
|
||||
const UnicodeString* getAmPmStrings(t_int32& count) const;
|
||||
|
||||
/**
|
||||
* Sets ampm strings. For example: "AM" and "PM".
|
||||
* @param newAmpms the new ampm strings. (not adopted; caller retains ownership)
|
||||
*/
|
||||
void setAmPmStrings(const UnicodeString* ampms, t_int32 count);
|
||||
|
||||
/**
|
||||
* Gets timezone strings. These strings are stored in a 2-dimensional array.
|
||||
* @param rowCount Output param to receive number of rows.
|
||||
* @param columnCount Output param to receive number of columns.
|
||||
* @return The timezone strings as a 2-d array. (DateFormatSymbols retains ownership.)
|
||||
*/
|
||||
const UnicodeString** getZoneStrings(t_int32& rowCount, t_int32& columnCount) const;
|
||||
|
||||
/**
|
||||
* Sets timezone strings. These strings are stored in a 2-dimensional array.
|
||||
* @param strings The timezone strings as a 2-d array to be copied. (not adopted; caller retains ownership)
|
||||
* @param rowCount The number of rows (count of first index).
|
||||
* @param columnCount The number of columns (count of second index).
|
||||
*/
|
||||
void setZoneStrings(const UnicodeString* const* strings, t_int32 rowCount, t_int32 columnCount);
|
||||
|
||||
/**
|
||||
* Get the non-localized date-time pattern characters.
|
||||
*/
|
||||
static const UnicodeString& getPatternChars() { return fgPatternChars; }
|
||||
|
||||
/**
|
||||
* Gets localized date-time pattern characters. For example: 'u', 't', etc.
|
||||
* @return the localized date-time pattern characters.
|
||||
*/
|
||||
UnicodeString& getLocalPatternChars(UnicodeString& result) const;
|
||||
|
||||
/**
|
||||
* Sets localized date-time pattern characters. For example: 'u', 't', etc.
|
||||
* @param newLocalPatternChars the new localized date-time
|
||||
* pattern characters.
|
||||
*/
|
||||
void setLocalPatternChars(const UnicodeString& newLocalPatternChars);
|
||||
|
||||
private:
|
||||
friend class SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* Era strings. For example: "AD" and "BC".
|
||||
*/
|
||||
UnicodeString* fEras;
|
||||
t_int32 fErasCount;
|
||||
|
||||
/**
|
||||
* Month strings. For example: "January", "February", etc.
|
||||
*/
|
||||
UnicodeString* fMonths;
|
||||
t_int32 fMonthsCount;
|
||||
|
||||
/**
|
||||
* Short month strings. For example: "Jan", "Feb", etc.
|
||||
*/
|
||||
UnicodeString* fShortMonths;
|
||||
t_int32 fShortMonthsCount;
|
||||
|
||||
/**
|
||||
* Weekday strings. For example: "Sunday", "Monday", etc.
|
||||
*/
|
||||
UnicodeString* fWeekdays;
|
||||
t_int32 fWeekdaysCount;
|
||||
|
||||
/**
|
||||
* Short weekday strings. For example: "Sun", "Mon", etc.
|
||||
*/
|
||||
UnicodeString* fShortWeekdays;
|
||||
t_int32 fShortWeekdaysCount;
|
||||
|
||||
/**
|
||||
* Ampm strings. For example: "AM" and "PM".
|
||||
*/
|
||||
UnicodeString* fAmPms;
|
||||
t_int32 fAmPmsCount;
|
||||
|
||||
/**
|
||||
* The format data of all the timezones in this locale.
|
||||
*/
|
||||
UnicodeString** fZoneStrings;
|
||||
t_int32 fZoneStringsRowCount;
|
||||
t_int32 fZoneStringsColCount;
|
||||
|
||||
/**
|
||||
* Localized date-time pattern characters. For example: use 'u' as 'y'.
|
||||
*/
|
||||
UnicodeString fLocalPatternChars;
|
||||
|
||||
/**
|
||||
* Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All
|
||||
* locales use the same these unlocalized pattern characters.
|
||||
*/
|
||||
static UnicodeString fgPatternChars;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Called by the constructors to actually load data from the resources
|
||||
*/
|
||||
void initializeData(const Locale&, ErrorCode& status, t_bool useLastResortData = FALSE);
|
||||
|
||||
/**
|
||||
* Copy or alias an array in another object, as appropriate.
|
||||
*/
|
||||
void assignArray(UnicodeString*& dstArray,
|
||||
t_int32& dstCount,
|
||||
const UnicodeString* srcArray,
|
||||
t_int32 srcCount,
|
||||
const DateFormatSymbols& other,
|
||||
int which);
|
||||
|
||||
/**
|
||||
* Return true if the given arrays' contents are equal, or if the arrays are
|
||||
* identical (pointers are equal).
|
||||
*/
|
||||
static t_bool arrayCompare(const UnicodeString* array1,
|
||||
const UnicodeString* array2,
|
||||
t_int32 count);
|
||||
|
||||
/**
|
||||
* Create a copy, in fZoneStrings, of the given zone strings array. The
|
||||
* member variables fZoneStringsRowCount and fZoneStringsColCount should be
|
||||
* set already by the caller. The fIsOwned flags are not checked or set by
|
||||
* this method; that is the caller's responsibility.
|
||||
*/
|
||||
void createZoneStrings(const UnicodeString *const * otherStrings);
|
||||
|
||||
/**
|
||||
* Delete all the storage owned by this object and reset the fIsOwned flag
|
||||
* to indicate that arrays have been deleted.
|
||||
*/
|
||||
void dispose();
|
||||
|
||||
/**
|
||||
* Delete just the zone strings, if they are owned by this object. This
|
||||
* method does NOT modify fIsOwned; the caller must handle that.
|
||||
*/
|
||||
void disposeZoneStrings();
|
||||
|
||||
/**
|
||||
* These are static arrays we use only in the case where we have no
|
||||
* resource data.
|
||||
*/
|
||||
static const UnicodeString kLastResortMonthNames[];
|
||||
static const UnicodeString kLastResortDayNames[];
|
||||
static const UnicodeString kLastResortAmPmMarkers[];
|
||||
static const UnicodeString kLastResortEras[];
|
||||
static const UnicodeString kLastResortZoneStrings[];
|
||||
static UnicodeString** fgLastResortZoneStrings;
|
||||
|
||||
/**
|
||||
* The member fIsOwned is a bit field with flags indicating which of the arrays
|
||||
* we own. This is necessary since the user may alter our symbols, but in
|
||||
* most cases, will not, so we do not want to copy these arrays unless
|
||||
* necessary.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
ERAS,
|
||||
MONTHS,
|
||||
SHORT_MONTHS,
|
||||
WEEKDAYS,
|
||||
SHORT_WEEKDAYS,
|
||||
AM_PMS,
|
||||
ZONE_STRINGS
|
||||
};
|
||||
t_uint8 fIsOwned;
|
||||
|
||||
/**
|
||||
* Sets the fIsOwned flag for the specfied string array
|
||||
*/
|
||||
void setIsOwned(int which, t_bool isOwned);
|
||||
|
||||
/**
|
||||
* Tests the fIsOwned flag for the specified string array
|
||||
*/
|
||||
t_bool isOwned(int which) const;
|
||||
};
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
inline void
|
||||
DateFormatSymbols::setIsOwned(int which, t_bool isOwned)
|
||||
{
|
||||
fIsOwned = ( fIsOwned & ~(1 << which) ) | ( (isOwned ? 1 : 0) << which );
|
||||
}
|
||||
|
||||
inline t_bool
|
||||
DateFormatSymbols::isOwned(int which) const
|
||||
{
|
||||
return ( (fIsOwned >> which) & 1 ) != 0;
|
||||
}
|
||||
|
||||
#endif // _DTFMTSYM
|
||||
//eof
|
|
@ -0,0 +1,142 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ENCONV_H
|
||||
#define ENCONV_H
|
||||
|
||||
#include "nlsxp.h"
|
||||
|
||||
typedef struct _NLS_AUTO_DETECT_RESULT
|
||||
{
|
||||
const char* fEncoding;
|
||||
uint32 fFeatures;
|
||||
uint32 fFlaws;
|
||||
uint32 fErrors;
|
||||
} NLS_AUTO_DETECT_RESULT;
|
||||
|
||||
#ifndef NLS_CPLUSPLUS
|
||||
|
||||
typedef struct _EncodingConverter EncodingConverter;
|
||||
typedef struct _EncondingConverterList EncondingConverterList;
|
||||
|
||||
#else
|
||||
|
||||
typedef struct OpaqueCCCDataObject *CCCDataObject;
|
||||
|
||||
//
|
||||
// Forward Delclartion of libnls private classes
|
||||
//
|
||||
class TEncodingRegistry;
|
||||
class TEncodingConverter;
|
||||
class TEncodingEntry;
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
class NLSCNVAPI_PUBLIC_CLASS EncodingConverter
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Constructor/destructor
|
||||
*/
|
||||
EncodingConverter(const char *from_charset, const char *to_charset);
|
||||
~EncodingConverter();
|
||||
|
||||
size_t convert(const byte *inputBuffer, size_t inputBufferLength,
|
||||
byte * outputBuffer, size_t outputBufferLength);
|
||||
|
||||
NLS_ErrorCode status();
|
||||
void reset();
|
||||
|
||||
/* If output buffer was two small, remainder can be retrieved */
|
||||
size_t remainderSize();
|
||||
size_t nextBuffer(byte * buffer, size_t bufferSize);
|
||||
|
||||
/* If conversion was incomplete there will be bytes leftover*/
|
||||
size_t leftoverSize();
|
||||
size_t leftover(byte * outputBuffer, size_t outputBufferLength);
|
||||
|
||||
static nlsBool exists(const char *from_charset, const char *to_charset);
|
||||
static const char* normalizedEncodingName(const char* encoding);
|
||||
static const char* normalizedJavaName(const char* javaName);
|
||||
static const char* javaEncodingName(const char* encoding);
|
||||
static size_t resultBufferSize(const byte *buffer, size_t length,
|
||||
const char *from_charset, const char *to_charset);
|
||||
static void registerStaticLibrary(NLS_StaticConverterRegistry ImportStaticEntryList);
|
||||
|
||||
/* Data directory set & get */
|
||||
static const char* getDataDirectory();
|
||||
static void setDataDirectory(const char* path);
|
||||
static NLS_ErrorCode initializeEncodingRegistry(void);
|
||||
static TEncodingRegistry* getEncodingRegistry(void);
|
||||
static void deleteEncodingRegistry(void);
|
||||
|
||||
private:
|
||||
int16 intermidiateCSIDForUnicodeConversion(int16 csid);
|
||||
size_t unicodeStringLength(UniChar *ustr);
|
||||
|
||||
NLS_ErrorCode fStatus;
|
||||
const char* fFromCharset;
|
||||
const char* fToCharset;
|
||||
CCCDataObject fObj;
|
||||
CCCDataObject fPreUniConvObj;
|
||||
CCCDataObject fPostUniConvObj;
|
||||
size_t fLeftOverSize;
|
||||
size_t fLeftOverAllocatedSize;
|
||||
byte* fLeftOverBuffer;
|
||||
size_t fRemSize;
|
||||
size_t fRemAllocatedSize;
|
||||
byte* fRemBuffer;
|
||||
TEncodingConverter *fEngine;
|
||||
|
||||
static char* fgConverterPath;
|
||||
static const char* kDefaultConverterPath;
|
||||
static TEncodingRegistry* fgRegistry;
|
||||
|
||||
};
|
||||
|
||||
class NLSCNVAPI_PUBLIC_CLASS EncondingConverterList
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Constructor/destructor
|
||||
*/
|
||||
EncondingConverterList(const char *from_charset, const char *to_charset);
|
||||
~EncondingConverterList();
|
||||
|
||||
size_t count();
|
||||
void index(size_t number, char *from_charset, char *to_charset);
|
||||
|
||||
private:
|
||||
NLS_ErrorCode fStatus;
|
||||
const char* fFromCharset;
|
||||
const char* fToCharset;
|
||||
size_t fCount;
|
||||
const char** fFromArray;
|
||||
const char** fToArray;
|
||||
TEncodingRegistry* fRegistry;
|
||||
};
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef NLS_CPLUSPLUS */
|
||||
#endif /* #ifndef ENCONV_H */
|
|
@ -0,0 +1,536 @@
|
|||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1996 *
|
||||
* (C) Copyright International Business Machines Corporation, 1996 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
*
|
||||
* File locid.h
|
||||
*
|
||||
* Created by: Helena Shih
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/11/97 aliu Changed gLocPath to fgLocPath and added methods to
|
||||
* get and set it.
|
||||
* 04/02/97 aliu Made operator!= inline; fixed return value of getName().
|
||||
* 04/15/97 aliu Cleanup for AIX/Win32.
|
||||
* 04/24/97 aliu Numerous changes per code review.
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _LOCID
|
||||
#define _LOCID
|
||||
|
||||
#ifndef _UNISTRING
|
||||
#include "unistring.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
* A <code>Locale</code> object represents a specific geographical, political,
|
||||
* or cultural region. An operation that requires a <code>Locale</code> to perform
|
||||
* its task is called <em>locale-sensitive</em> and uses the <code>Locale</code>
|
||||
* to tailor information for the user. For example, displaying a number
|
||||
* is a locale-sensitive operation--the number should be formatted
|
||||
* according to the customs/conventions of the user's native country,
|
||||
* region, or culture.
|
||||
*
|
||||
* <P>
|
||||
* You create a <code>Locale</code> object using one of the two constructors in
|
||||
* this class:
|
||||
* <blockquote>
|
||||
* <pre>
|
||||
* . Locale(String language, String country)
|
||||
* . Locale(String language, String country, String variant)
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
* The first argument to both constructors is a valid <STRONG>ISO
|
||||
* Language Code.</STRONG> These codes are the lower-case two-letter
|
||||
* codes as defined by ISO-639.
|
||||
* You can find a full list of these codes at a number of sites, such as:
|
||||
* <BR><a href ="http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt">
|
||||
* <code>http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt</code></a>
|
||||
*
|
||||
* <P>
|
||||
* The second argument to both constructors is a valid <STRONG>ISO Country
|
||||
* Code.</STRONG> These codes are the upper-case two-letter codes
|
||||
* as defined by ISO-3166.
|
||||
* You can find a full list of these codes at a number of sites, such as:
|
||||
* <BR><a href="http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html">
|
||||
* <code>http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html</code></a>
|
||||
*
|
||||
* <P>
|
||||
* The second constructor requires a third argument--the <STRONG>Variant.</STRONG>
|
||||
* The Variant codes are vendor and browser-specific.
|
||||
* For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX.
|
||||
* Where there are two variants, separate them with an underscore, and
|
||||
* put the most important one first. For
|
||||
* example, a Traditional Spanish collation might be referenced, with
|
||||
* "ES", "ES", "Traditional_WIN".
|
||||
*
|
||||
* <P>
|
||||
* Because a <code>Locale</code> object is just an identifier for a region,
|
||||
* no validity check is performed when you construct a <code>Locale</code>.
|
||||
* If you want to see whether particular resources are available for the
|
||||
* <code>Locale</code> you construct, you must query those resources. For
|
||||
* example, ask the <code>NumberFormat</code> for the locales it supports
|
||||
* using its <code>getAvailableLocales</code> method.
|
||||
* <BR><STRONG>Note:</STRONG> When you ask for a resource for a particular
|
||||
* locale, you get back the best available match, not necessarily
|
||||
* precisely what you asked for. For more information, look at
|
||||
* <a href="java.util.ResourceBundle.html"><code>ResourceBundle</code></a>.
|
||||
*
|
||||
* <P>
|
||||
* The <code>Locale</code> class provides a number of convenient constants
|
||||
* that you can use to create <code>Locale</code> objects for commonly used
|
||||
* locales. For example, the following refers to a <code>Locale</code> object
|
||||
* for the United States:
|
||||
* <blockquote>
|
||||
* <pre>
|
||||
* . Locale::US
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
*
|
||||
* <P>
|
||||
* Once you've created a <code>Locale</code> you can query it for information about
|
||||
* itself. Use <code>getCountry</code> to get the ISO Country Code and
|
||||
* <code>getLanguage</code> to get the ISO Language Code. You can
|
||||
* use <code>getDisplayCountry</code> to get the
|
||||
* name of the country suitable for displaying to the user. Similarly,
|
||||
* you can use <code>getDisplayLanguage</code> to get the name of
|
||||
* the language suitable for displaying to the user. Interestingly,
|
||||
* the <code>getDisplayXXX</code> methods are themselves locale-sensitive
|
||||
* and have two versions: one that uses the default locale and one
|
||||
* that takes a locale as an argument and displays the name or country in
|
||||
* a language appropriate to that locale.
|
||||
*
|
||||
* <P>
|
||||
* The TIFC provides a number of classes that perform locale-sensitive
|
||||
* operations. For example, the <code>NumberFormat</code> class formats
|
||||
* numbers, currency, or percentages in a locale-sensitive manner. Classes
|
||||
* such as <code>NumberFormat</code> have a number of convenience methods
|
||||
* for creating a default object of that type. For example, the
|
||||
* <code>NumberFormat</code> class provides these three convenience methods
|
||||
* for creating a default <code>NumberFormat</code> object:
|
||||
* <blockquote>
|
||||
* <pre>
|
||||
* . NumberFormat.getInstance()
|
||||
* . NumberFormat.getCurrencyInstance()
|
||||
* . NumberFormat.getPercentInstance()
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
* Each of these methods has two variants; one with an explicit locale
|
||||
* and one without; the latter using the default locale.
|
||||
* <blockquote>
|
||||
* <pre>
|
||||
* . NumberFormat.getInstance(myLocale)
|
||||
* . NumberFormat.getCurrencyInstance(myLocale)
|
||||
* . NumberFormat.getPercentInstance(myLocale)
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
* A <code>Locale</code> is the mechanism for identifying the kind of object
|
||||
* (<code>NumberFormat</code>) that you would like to get. The locale is
|
||||
* <STRONG>just</STRONG> a mechanism for identifying objects,
|
||||
* <STRONG>not</STRONG> a container for the objects themselves.
|
||||
*
|
||||
* <P>
|
||||
* Each class that performs locale-sensitive operations allows you
|
||||
* to get all the available objects of that type. You can sift
|
||||
* through these objects by language, country, or variant,
|
||||
* and use the display names to present a menu to the user.
|
||||
* For example, you can create a menu of all the collation objects
|
||||
* suitable for a given language. Such classes implement these
|
||||
* three class methods:
|
||||
* <blockquote>
|
||||
* <pre>
|
||||
* . static Locale* getAvailableLocales(t_int32& numLocales)
|
||||
* . static UnicodeString& getDisplayName(const Locale& objectLocale,
|
||||
* . const Locale& displayLocale,
|
||||
* . UnicodeString& displayName)
|
||||
* . static UnicodeString& getDisplayName(const Locale& objectLocale,
|
||||
* . UnicodeString& displayName)
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
*/
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
class T_UTILITY_API Locale
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Useful constants for language.
|
||||
*/
|
||||
static const Locale ENGLISH;
|
||||
static const Locale FRENCH;
|
||||
static const Locale GERMAN;
|
||||
static const Locale ITALIAN;
|
||||
static const Locale JAPANESE;
|
||||
static const Locale KOREAN;
|
||||
static const Locale CHINESE;
|
||||
static const Locale SCHINESE; // Simplified Chinese
|
||||
static const Locale TCHINESE; // Traditional Chinese
|
||||
|
||||
/**
|
||||
* Useful constants for country.
|
||||
*/
|
||||
static const Locale FRANCE;
|
||||
static const Locale GERMANY;
|
||||
static const Locale ITALY;
|
||||
static const Locale JAPAN;
|
||||
static const Locale KOREA;
|
||||
static const Locale CHINA; // Alias for PRC
|
||||
static const Locale PRC; // People's Republic of China
|
||||
static const Locale TAIWAN; // Republic of China
|
||||
static const Locale UK;
|
||||
static const Locale US;
|
||||
static const Locale CANADA;
|
||||
static const Locale CANADA_FRENCH;
|
||||
|
||||
/**
|
||||
* Construct an empty locale. It's only used when a fill-in parameter is
|
||||
* needed.
|
||||
*/
|
||||
Locale();
|
||||
|
||||
/**
|
||||
* Construct an locale from language.
|
||||
*
|
||||
* @param language Lowercase two-letter ISO-639 code.
|
||||
*/
|
||||
Locale( const UnicodeString& newLanguage);
|
||||
|
||||
/**
|
||||
* Construct a locale from language, country.
|
||||
*
|
||||
* @param language Uppercase two-letter ISO-639 code.
|
||||
* @param country Uppercase two-letter ISO-3166 code.
|
||||
*/
|
||||
Locale( const UnicodeString& language,
|
||||
const UnicodeString& country);
|
||||
|
||||
/**
|
||||
* Construct a locale from language, country, variant.
|
||||
*
|
||||
* @param language Lowercase two-letter ISO-639 code.
|
||||
* @param country Uppercase two-letter ISO-3166 code.
|
||||
* @param variant Uppercase vendor and browser specific code. See class
|
||||
* description.
|
||||
*/
|
||||
Locale( const UnicodeString& language,
|
||||
const UnicodeString& country,
|
||||
const UnicodeString& variant);
|
||||
|
||||
/**
|
||||
* Initializes an Locale object from another Locale object.
|
||||
*
|
||||
* @param other The Locale object being copied in.
|
||||
*/
|
||||
Locale(const Locale& other);
|
||||
|
||||
/**
|
||||
* Initializes an Locale object from char*
|
||||
*
|
||||
* lang can be any one of lang, lang_co, or lang_co_variant
|
||||
*/
|
||||
Locale(const char *loc_id);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~Locale() { }
|
||||
/**
|
||||
* Replaces the entire contents of *this with the specified value.
|
||||
*
|
||||
* @param other The Locale object being copied in.
|
||||
* @return *this
|
||||
*/
|
||||
Locale& operator=(const Locale& other);
|
||||
|
||||
/**
|
||||
* Checks if two locale keys are the same.
|
||||
*
|
||||
* @param other The locale key object to be compared with this.
|
||||
* @return True if the two locale keys are the same, false otherwise.
|
||||
*/
|
||||
t_bool operator==(const Locale& other) const;
|
||||
|
||||
/**
|
||||
* Checks if two locale keys are not the same.
|
||||
*
|
||||
* @param other The locale key object to be compared with this.
|
||||
* @return True if the two locale keys are not the same, false
|
||||
* otherwise.
|
||||
*/
|
||||
t_bool operator!=(const Locale& other) const;
|
||||
|
||||
/**
|
||||
* Common methods of getting the current default Locale. Used for the
|
||||
* presentation: menus, dialogs, etc. Generally set once when your applet or
|
||||
* application is initialized, then never reset. (If you do reset the
|
||||
* default locale, you probably want to reload your GUI, so that the change
|
||||
* is reflected in your interface.)
|
||||
*
|
||||
* More advanced programs will allow users to use different locales for
|
||||
* different fields, e.g. in a spreadsheet.
|
||||
*
|
||||
* Note that the initial setting will match the host system.
|
||||
*/
|
||||
static const Locale& getDefault();
|
||||
|
||||
/**
|
||||
* Sets the default. Normally set once at the beginning of applet or
|
||||
* application, then never reset. setDefault does NOT reset the host locale.
|
||||
*
|
||||
* @param newLocale Locale to set to.
|
||||
*/
|
||||
static void setDefault(const Locale& newLocale,
|
||||
ErrorCode& success);
|
||||
|
||||
/**
|
||||
* Fills in "lang" with the locale's two-letter ISO-639 language code.
|
||||
* @param lang Receives the language code.
|
||||
* @return A reference to "lang".
|
||||
*/
|
||||
UnicodeString& getLanguage( UnicodeString& lang) const;
|
||||
/**
|
||||
* Fills in "cntry" with the locale's two-letter ISO-3166 country code.
|
||||
* @param cntry Receives the country code.
|
||||
* @return A reference to "cntry".
|
||||
*/
|
||||
UnicodeString& getCountry( UnicodeString& cntry) const;
|
||||
/**
|
||||
* Fills in "var" with the locale's variant code.
|
||||
* @param var Receives the variant code.
|
||||
* @return A reference to "var".
|
||||
*/
|
||||
UnicodeString& getVariant( UnicodeString& var) const;
|
||||
|
||||
/**
|
||||
* Fills in "name" the programmatic name of the entire locale, with the language,
|
||||
* country and variant separated by underbars. If a field is missing, at
|
||||
* most one underbar will occur. Example: "en", "de_DE", "en_US_WIN",
|
||||
* "de_POSIX", "fr_MAC"
|
||||
* @param var Receives the programmatic locale name.
|
||||
* @return A reference to "name".
|
||||
*/
|
||||
UnicodeString& getName( UnicodeString& name) const;
|
||||
|
||||
/**
|
||||
* Fills in "name" with the locale's three-letter language code, as specified
|
||||
* in ISO draft standard ISO-639-2..
|
||||
* @param name Receives the three-letter language code.
|
||||
* @return A reference to "name".
|
||||
*/
|
||||
UnicodeString& getISO3Language(UnicodeString& name) const;
|
||||
|
||||
/**
|
||||
* Fills in "name" with the locale's three-letter ISO-3166 country code.
|
||||
* @param name Receives the three-letter country code.
|
||||
* @return A reference to "name".
|
||||
*/
|
||||
UnicodeString& getISO3Country( UnicodeString& name) const;
|
||||
|
||||
/**
|
||||
* Returns the Windows LCID value corresponding to this locale.
|
||||
* This value is stored in the resource data for the locale as a one-to-four-digit
|
||||
* hexadecimal number. If the resource is missing, in the wrong format, or
|
||||
* there is no Windows LCID value that corresponds to this locale, returns 0.
|
||||
*/
|
||||
t_uint32 getLCID() const;
|
||||
|
||||
/**
|
||||
* Fills in "dispLang" with the name of this locale's language in a format suitable for
|
||||
* user display in the default locale. For example, if the locale's language code is
|
||||
* "fr" and the default locale's language code is "en", this function would set
|
||||
* dispLang to "French".
|
||||
* @param dispLang Receives the language's display name.
|
||||
* @return A reference to "dispLang".
|
||||
*/
|
||||
UnicodeString& getDisplayLanguage(UnicodeString& dispLang) const;
|
||||
|
||||
/**
|
||||
* Fills in "dispLang" with the name of this locale's language in a format suitable for
|
||||
* user display in the locale specified by "inLocale". For example, if the locale's
|
||||
* language code is "en" and inLocale's language code is "fr", this function would set
|
||||
* dispLang to "Anglais".
|
||||
* @param inLocale Specifies the locale to be used to display the name. In other words,
|
||||
* if the locale's language code is "en", passing Locale::FRENCH for
|
||||
* inLocale would result in "Anglais", while passing Locale::GERMAN
|
||||
* for inLocale would result in "Englisch".
|
||||
* @param dispLang Receives the language's display name.
|
||||
* @return A reference to "dispLang".
|
||||
*/
|
||||
UnicodeString& getDisplayLanguage( const Locale& inLocale,
|
||||
UnicodeString& dispLang) const;
|
||||
/**
|
||||
* Fills in "dispCountry" with the name of this locale's country in a format suitable
|
||||
* for user display in the default locale. For example, if the locale's country code
|
||||
* is "FR" and the default locale's language code is "en", this function would set
|
||||
* dispCountry to "France".
|
||||
* @param dispCountry Receives the country's display name.
|
||||
* @return A reference to "dispCountry".
|
||||
*/
|
||||
UnicodeString& getDisplayCountry( UnicodeString& dispCountry) const;
|
||||
/**
|
||||
* Fills in "dispCountry" with the name of this locale's country in a format suitable
|
||||
* for user display in the locale specified by "inLocale". For example, if the locale's
|
||||
* country code is "US" and inLocale's language code is "fr", this function would set
|
||||
* dispCountry to "Etats-Unis".
|
||||
* @param inLocale Specifies the locale to be used to display the name. In other
|
||||
* words, if the locale's country code is "US", passing
|
||||
* Locale::FRENCH for inLocale would result in "États-Unis", while
|
||||
* passing Locale::GERMAN for inLocale would result in
|
||||
* "Vereinigte Staaten".
|
||||
* @param dispCountry Receives the country's display name.
|
||||
* @return A reference to "dispCountry".
|
||||
*/
|
||||
UnicodeString& getDisplayCountry( const Locale& inLocale,
|
||||
UnicodeString& dispCountry) const;
|
||||
|
||||
/**
|
||||
* Fills in "dispVar" with the name of this locale's variant code in a format suitable
|
||||
* for user display in the default locale.
|
||||
* @param dispVar Receives the variant's name.
|
||||
* @return A reference to "dispVar".
|
||||
*/
|
||||
UnicodeString& getDisplayVariant( UnicodeString& dispVar) const;
|
||||
/**
|
||||
* Fills in "dispVar" with the name of this locale's variant code in a format
|
||||
* suitable for user display in the locale specified by "inLocale".
|
||||
* @param inLocale Specifies the locale to be used to display the name.
|
||||
* @param dispVar Receives the variant's display name.
|
||||
* @return A reference to "dispVar".
|
||||
*/
|
||||
UnicodeString& getDisplayVariant( const Locale& inLocale,
|
||||
UnicodeString& dispVar) const;
|
||||
/**
|
||||
* Fills in "name" with the name of this locale in a format suitable for user display
|
||||
* in the default locale. This function uses getDisplayLanguage(), getDisplayCountry(),
|
||||
* and getDisplayVariant() to do its work, and outputs the display name in the format
|
||||
* "language (country[,variant])". For example, if the default locale is en_US, then
|
||||
* fr_FR's display name would be "French (France)", and es_MX_Traditional's display name
|
||||
* would be "Spanish (Mexico,Traditional)".
|
||||
* @param name Receives the locale's display name.
|
||||
* @return A reference to "name".
|
||||
*/
|
||||
UnicodeString& getDisplayName( UnicodeString& name) const;
|
||||
/**
|
||||
* Fills in "name" with the name of this locale in a format suitable for user display
|
||||
* in the locale specfied by "inLocale". This function uses getDisplayLanguage(),
|
||||
* getDisplayCountry(), and getDisplayVariant() to do its work, and outputs the display
|
||||
* name in the format "language (country[,variant])". For example, if inLocale is
|
||||
* fr_FR, then en_US's display name would be "Anglais (États-Unis)", and no_NO_NY's
|
||||
* display name would be "norvégien (Norvège,NY)".
|
||||
* @param inLocale Specifies the locale to be used to display the name.
|
||||
* @param name Receives the locale's display name.
|
||||
* @return A reference to "name".
|
||||
*/
|
||||
UnicodeString& getDisplayName( const Locale& inLocale,
|
||||
UnicodeString& name) const;
|
||||
/**
|
||||
* Generates a hash code for the locale. Since Locales are often used in hashtables,
|
||||
* caches the value for speed.
|
||||
*/
|
||||
t_int32 hashCode() const;
|
||||
|
||||
/**
|
||||
* Retuns a list of all installed locales.
|
||||
* @param count Receives the number of locales in the list.
|
||||
* @return A pointer to an array of Locale objects. This array is the list
|
||||
* of all locales with installed resource files. The called does NOT
|
||||
* get ownership of this list, and must NOT delete it.
|
||||
*/
|
||||
static const Locale* getAvailableLocales(t_int32& count);
|
||||
|
||||
/**
|
||||
* Get the path to the ResourceBundle locale files. This path will be a
|
||||
* platform-specific path name ending in a directory separator, so that file
|
||||
* names may be concatenated to it. This path may be changed by calling
|
||||
* setDataDirectory(). If setDataDirectory() has not been called yet,
|
||||
* getDataDirectory() will return a platform-dependent default path as
|
||||
* specified by TPlatformUtilities::getDefaultDataDirectory().
|
||||
*
|
||||
* @return Current data path.
|
||||
*/
|
||||
static const char* getDataDirectory();
|
||||
|
||||
/**
|
||||
* Set the path to the ResourceBundle locale files. After making this call,
|
||||
* all objects in the Unicode Analytics package will read ResourceBundle
|
||||
* data files in the specified directory in order to obtain locale data.
|
||||
*
|
||||
* @param path The new data path to be set to.
|
||||
*/
|
||||
static void setDataDirectory(const char* path);
|
||||
|
||||
/**
|
||||
* Performs the functions necessary to terminate the library.
|
||||
*/
|
||||
static void terminateLibrary(void);
|
||||
|
||||
private:
|
||||
|
||||
enum EPOSIXPortion {
|
||||
LANGUAGE,
|
||||
COUNTRY,
|
||||
VARIANT
|
||||
};
|
||||
|
||||
static void parsePOSIXID(const UnicodeString& str,
|
||||
UnicodeString& result,
|
||||
EPOSIXPortion part);
|
||||
private:
|
||||
// These strings describe the resources we attempt to load from
|
||||
// the locale ResourceBundle data file.
|
||||
static const char* kLocaleString;
|
||||
static const char* kShortLanguage;
|
||||
static const char* kShortCountry;
|
||||
static const char* kLocaleID;
|
||||
static const char* kLanguages;
|
||||
static const char* kCountries;
|
||||
|
||||
// The default locale we use if we can't get one from the host.
|
||||
static const char* kDefaultLocaleOfLastResort;
|
||||
|
||||
static Locale defaultLocale;
|
||||
static Locale* localeList;
|
||||
static t_int32 localeListCount;
|
||||
static char* fgDataDirectory;
|
||||
|
||||
UnicodeString id;
|
||||
};
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
|
||||
inline t_int32
|
||||
Locale::hashCode() const
|
||||
{
|
||||
return( id.hashCode() );
|
||||
}
|
||||
|
||||
inline t_bool
|
||||
Locale::operator==( const Locale& other) const
|
||||
{
|
||||
return (this == &other || id == other.id);
|
||||
}
|
||||
|
||||
inline t_bool
|
||||
Locale::operator!=(const Locale& other) const
|
||||
{
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,36 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _NLS_H
|
||||
#define _NLS_H
|
||||
|
||||
|
||||
#include "nlsxp.h"
|
||||
|
||||
#include "nlsuni.h"
|
||||
#include "nlsenc.h"
|
||||
#include "nlsloc.h"
|
||||
#include "nlscol.h"
|
||||
#include "nlsres.h"
|
||||
#include "nlsutl.h"
|
||||
#include "nlsbrk.h"
|
||||
#include "nlsmsg.h"
|
||||
#include "nlsfmt.h"
|
||||
|
||||
#endif /* _NLS_H */
|
||||
|
|
@ -0,0 +1,220 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _NLSBRK_H
|
||||
#define _NLSBRK_H
|
||||
|
||||
|
||||
#include "nlsxp.h"
|
||||
#include "nlsuni.h"
|
||||
#include "nlsloc.h"
|
||||
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
#include "txtbdry.h"
|
||||
#endif
|
||||
|
||||
|
||||
NLS_BEGIN_PROTOS
|
||||
|
||||
/******************** TextBoundary Data Types ************************/
|
||||
|
||||
#ifndef NLS_CPLUSPLUS
|
||||
typedef struct _TextBoundary TextBoundary;
|
||||
#endif
|
||||
|
||||
enum _NLS_TextBoundaryDone {
|
||||
NLS_TextBoundaryDone = (TextOffset)-1L
|
||||
};
|
||||
|
||||
/******************** TextBoundary Constructor functions ************************/
|
||||
|
||||
/** NLS_NewCharacterTextBoundary
|
||||
*
|
||||
* Create a Character Break Text Boundry for the given locale. Locale
|
||||
* may be NULL, at which point the default locale will be used.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_NEW_TEXT_BOUNDARY_FAILED
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewCharacterTextBoundary(TextBoundary ** result,
|
||||
const Locale* locale);
|
||||
|
||||
/** NLS_NewWordTextBoundary
|
||||
*
|
||||
* Create a Word break text boundry for the given locale. Locale
|
||||
* may be NULL, at which point the default locale will be used.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_NEW_TEXT_BOUNDARY_FAILED
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewWordTextBoundary(TextBoundary ** result,
|
||||
const Locale* locale);
|
||||
|
||||
/** NLS_NewLineTextBoundary
|
||||
*
|
||||
* Create a Line Break Text Boundry for the given locale. Locale
|
||||
* may be NULL, at which point the default locale will be used.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_NEW_TEXT_BOUNDARY_FAILED
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewLineTextBoundary(TextBoundary ** result,
|
||||
const Locale* locale);
|
||||
|
||||
/** NLS_NewSentenceTextBoundary
|
||||
*
|
||||
* Create a Sentence Break Text Boundry for the given locale. Locale
|
||||
* may be NULL, at which point the default locale will be used.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_NEW_TEXT_BOUNDARY_FAILED
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewSentenceTextBoundary(TextBoundary ** result,
|
||||
const Locale* locale);
|
||||
|
||||
/********************* TextBoundary Destructor functions *******************************/
|
||||
|
||||
/* NLS_DeleteTextBoundary
|
||||
*
|
||||
* Destructor for an TextBoundary
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteTextBoundary(TextBoundary * that);
|
||||
|
||||
/******************** TextBoundary API ************************/
|
||||
|
||||
/** NLS_TextBoundarySetText
|
||||
*
|
||||
* Set the text for the text boundry object. Replaces any text
|
||||
* that may be set, and resets the state of the text boundry
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_TextBoundarySetText(TextBoundary * that,
|
||||
const UnicodeString* text);
|
||||
|
||||
/** NLS_TextBoundarySetTextUniChar
|
||||
* Set the text for the text boundry object. Replaces any text
|
||||
* that may be set, and resets the state of the text boundry
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
* NLS_NEW_UNICODESTRING_FAILED
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_TextBoundarySetTextUniChar(TextBoundary * that,
|
||||
const UniChar* text,
|
||||
size_t length);
|
||||
|
||||
|
||||
/** NLS_TextBoundaryGetText
|
||||
*
|
||||
* Gets the text that is currently set on the text boundry.
|
||||
* May return NULL in the case of an error.
|
||||
*
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(const UnicodeString*)
|
||||
NLS_TextBoundaryGetText(TextBoundary * that);
|
||||
|
||||
/** NLS_TextBoundaryGetTextUniChar
|
||||
*
|
||||
* Gets the text that is currently set on the text boundry.
|
||||
* May return NULL in the case of an error.
|
||||
*
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(const UniChar*)
|
||||
NLS_TextBoundaryGetTextUniChar(TextBoundary * that);
|
||||
|
||||
/** NLS_TextBoundaryFirst
|
||||
*
|
||||
* Gets the offset of the first boundary. Moves the current break
|
||||
* state to the new offset. Will return the offset of the text boundary
|
||||
* or NLS_TextBoundryDone if there are no more boundry positions.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(TextOffset)
|
||||
NLS_TextBoundaryFirst(TextBoundary * that);
|
||||
|
||||
/** NLS_TextBoundaryLast
|
||||
*
|
||||
* Gets the offset of the Last boundary. Moves the current break
|
||||
* state to the new offset. Will return the offset of the text boundary
|
||||
* or NLS_TextBoundryDone if there are no more boundry positions.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(TextOffset)
|
||||
NLS_TextBoundaryLast(TextBoundary * that);
|
||||
|
||||
/** NLS_TextBoundaryNext
|
||||
*
|
||||
* Gets the offset of the Next boundary. Moves the current break
|
||||
* state to the new offset. Will return the offset of the text boundary
|
||||
* or NLS_TextBoundryDone if there are no more boundry positions.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(TextOffset)
|
||||
NLS_TextBoundaryNext(TextBoundary * that);
|
||||
|
||||
/** NLS_TextBoundryDone
|
||||
*
|
||||
* Gets the offset of the Previous boundary. Moves the current break
|
||||
* state to the new offset. Will return the offset of the text boundary
|
||||
* or NLS_TextBoundryDone if there are no more boundry positions.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(TextOffset)
|
||||
NLS_TextBoundaryPrevious(TextBoundary * that);
|
||||
|
||||
/** NLS_TextBoundaryCurrent
|
||||
*
|
||||
* Gets the offset of the Current boundary. Moves the current break
|
||||
* state to the new offset. Will return the offset of the text boundary
|
||||
* or NLS_TextBoundryDone if there are no more boundry positions.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(TextOffset)
|
||||
NLS_TextBoundaryCurrent(TextBoundary * that);
|
||||
|
||||
/** NLS_TextBoundaryNextAfter
|
||||
*
|
||||
* Gets the offset of the Next boundary after the TextOffset specified.
|
||||
* Moves the current break state to the new offset. Will return the offset
|
||||
* of the text boundary or NLS_TextBoundryDone if there are no more
|
||||
* boundry positions.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(TextOffset)
|
||||
NLS_TextBoundaryNextAfter(TextBoundary * that,
|
||||
TextOffset offset);
|
||||
|
||||
|
||||
/************************ End ******************************/
|
||||
|
||||
NLS_END_PROTOS
|
||||
#endif /* _NLSBRK_H */
|
||||
|
|
@ -0,0 +1,249 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NLSCAL_H
|
||||
#define _NLSCAL_H
|
||||
|
||||
|
||||
#include "nlsxp.h"
|
||||
#include "nlsuni.h"
|
||||
#include "nlsloc.h"
|
||||
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
#include "calendar.h"
|
||||
#include "timezone.h"
|
||||
#endif
|
||||
|
||||
|
||||
NLS_BEGIN_PROTOS
|
||||
|
||||
/******************** Formatting Data Types ************************/
|
||||
|
||||
#ifndef NLS_CPLUSPLUS
|
||||
typedef struct _Calendar Calendar;
|
||||
typedef struct _TimeZone TimeZone;
|
||||
#endif
|
||||
|
||||
typedef int NLS_DateTimeFormatType;
|
||||
enum _NLS_DateTimeFormatType {
|
||||
NLS_DATETIMEFORMAT_TYPE_FULL,
|
||||
NLS_DATETIMEFORMAT_TYPE_LONG,
|
||||
NLS_DATETIMEFORMAT_TYPE_MEDIUM,
|
||||
NLS_DATETIMEFORMAT_TYPE_SHORT,
|
||||
NLS_DATETIMEFORMAT_TYPE_DEFAULT = NLS_DATETIMEFORMAT_TYPE_MEDIUM,
|
||||
NLS_DATETIMEFORMAT_TYPE_DATE_OFFSET = 4,
|
||||
NLS_DATETIMEFORMAT_TYPE_NONE = -1,
|
||||
NLS_DATETIMEFORMAT_TYPE_DATE_TIME = 8
|
||||
};
|
||||
|
||||
typedef int NLS_CalendarDateFields;
|
||||
enum _NLS_CalendarDateFields {
|
||||
NLS_CALENDAR_ERA,
|
||||
NLS_CALENDAR_YEAR,
|
||||
NLS_CALENDAR_MONTH,
|
||||
NLS_CALENDAR_WEEK_OF_YEAR,
|
||||
NLS_CALENDAR_WEEK_OF_MONTH,
|
||||
NLS_CALENDAR_DATE,
|
||||
NLS_CALENDAR_DAY_OF_YEAR,
|
||||
NLS_CALENDAR_DAY_OF_WEEK,
|
||||
NLS_CALENDAR_DAY_OF_WEEK_IN_MONTH,
|
||||
NLS_CALENDAR_AM_PM,
|
||||
NLS_CALENDAR_HOUR,
|
||||
NLS_CALENDAR_HOUR_OF_DAY,
|
||||
NLS_CALENDAR_MINUTE,
|
||||
NLS_CALENDAR_SECOND,
|
||||
NLS_CALENDAR_MILLISECOND,
|
||||
NLS_CALENDAR_ZONE_OFFSET,
|
||||
NLS_CALENDAR_DST_OFFSET,
|
||||
NLS_CALENDAR_FIELD_COUNT
|
||||
};
|
||||
|
||||
typedef int NLS_CalendarDaysOfWeek;
|
||||
enum _NLS_CalendarDaysOfWeek {
|
||||
NLS_CALENDAR_SUNDAY = 1,
|
||||
NLS_CALENDAR_MONDAY,
|
||||
NLS_CALENDAR_TUESDAY,
|
||||
NLS_CALENDAR_WEDNESDAY,
|
||||
NLS_CALENDAR_THURSDAY,
|
||||
NLS_CALENDAR_FRIDAY,
|
||||
NLS_CALENDAR_SATURDAY
|
||||
};
|
||||
|
||||
typedef int NLS_CalendarMonths;
|
||||
enum _NLS_CalendarMonths {
|
||||
NLS_CALENDAR_JANUARY,
|
||||
NLS_CALENDAR_FEBRUARY,
|
||||
NLS_CALENDAR_MARCH,
|
||||
NLS_CALENDAR_APRIL,
|
||||
NLS_CALENDAR_MAY,
|
||||
NLS_CALENDAR_JUNE,
|
||||
NLS_CALENDAR_JULY,
|
||||
NLS_CALENDAR_AUGUST,
|
||||
NLS_CALENDAR_SEPTEMBER,
|
||||
NLS_CALENDAR_OCTOBER,
|
||||
NLS_CALENDAR_NOVEMBER,
|
||||
NLS_CALENDAR_DECEMBER,
|
||||
NLS_CALENDAR_UNDECIMBER
|
||||
};
|
||||
|
||||
typedef int NLS_CalendarAMPM;
|
||||
enum _NLS_CalendarAMPM {
|
||||
NLS_CALENDAR_AM,
|
||||
NLS_CALENDAR_PM
|
||||
};
|
||||
|
||||
/******************** Simple functions ************************/
|
||||
|
||||
NLSFMTAPI_PUBLIC(Date)
|
||||
NLS_GetCurrentDate();
|
||||
|
||||
|
||||
/******************** Constructor functions ************************/
|
||||
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewCalendar(Calendar ** result, const TimeZone* timeZone, const Locale* locale);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewCalendarCopy(Calendar ** result, const Calendar * calendar);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewCalendarDate(Calendar ** result, int32 year, int32 month, int32 date);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewCalendarDateTime(Calendar ** result, int32 year, int32 month, int32 date, int32 hour, int32 minute, int32 second);
|
||||
|
||||
NLSFMTAPI_PUBLIC(const TimeZone*)
|
||||
NLS_GetDefaultTimeZone();
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewTimeZone(TimeZone ** result, const UnicodeString* ID);
|
||||
|
||||
/********************* Destructor functions *******************************/
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteCalendar(Calendar * that);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteTimeZone(TimeZone * that);
|
||||
|
||||
/******************** API ************************/
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CalendarSetDate(Calendar * calendar, int32 year, int32 month, int32 date);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CalendarSetDateTime(Calendar * calendar, int32 year, int32 month, int32 date, int32 hour, int32 minute, int32 second);
|
||||
|
||||
NLSFMTAPI_PUBLIC(Date)
|
||||
NLS_CalendarGetTime(const Calendar * calendar);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CalendarSetTime(Calendar * calendar, Date date);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CalendarAdd(Calendar * calendar, NLS_CalendarDateFields field, int32 amount);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CalendarRoll(Calendar * calendar, NLS_CalendarDateFields field, nlsBool up);
|
||||
|
||||
NLSFMTAPI_PUBLIC(const TimeZone*)
|
||||
NLS_CalendarGetTimeZone(const Calendar * calendar);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CalendarSetTimeZone(Calendar * calendar, const TimeZone* timeZone);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CalendarClear(Calendar * calendar);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CalendarClearField(Calendar * calendar, NLS_CalendarDateFields field);
|
||||
|
||||
NLSFMTAPI_PUBLIC(int32)
|
||||
NLS_CalendarGetField(const Calendar * calendar, NLS_CalendarDateFields field);
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_CalendarFieldIsSet(const Calendar * calendar, NLS_CalendarDateFields field);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CalendarSetField(Calendar * calendar, NLS_CalendarDateFields field, int32 value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(int32)
|
||||
NLS_CalendarGetMinimum(const Calendar * calendar, NLS_CalendarDateFields field);
|
||||
|
||||
NLSFMTAPI_PUBLIC(int32)
|
||||
NLS_CalendarGetMaximum(const Calendar * calendar, NLS_CalendarDateFields field);
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_CalendarInDaylightTime(const Calendar * calendar);
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_CalendarIsEqual(const Calendar * calendar1, const Calendar * calendar2);
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_CalendarBefore(const Calendar * calendar1, const Calendar * calendar2);
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_CalendarAfter(const Calendar * calendar1, const Calendar * calendar2);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CalendarSetFirstDayOfWeek(Calendar* calendar, NLS_CalendarDaysOfWeek firstDay);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_CalendarDaysOfWeek)
|
||||
NLS_CalendarGetFirstDayOfWeek(const Calendar* calendar);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CalendarSetMinimalDaysInFirstWeek(Calendar* calendar, uint8 value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(uint8)
|
||||
NLS_CalendarGetMinimalDaysInFirstWeek(const Calendar* calendar);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_TimeZoneGetID(const TimeZone* zone, UnicodeString* IDResult);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_TimeZoneSetID(TimeZone* zone, const UnicodeString* IDResult);
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_TimeZoneEqual(const TimeZone* zone1, const TimeZone* zone2);
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_TimeZoneUseDaylightTime(const TimeZone* zone);
|
||||
|
||||
NLSFMTAPI_PUBLIC(int)
|
||||
NLS_TimeZoneGetOffset(const TimeZone* zone,
|
||||
uint8 era,
|
||||
int32 year,
|
||||
int32 month,
|
||||
int32 day,
|
||||
uint8 dayOfWeek,
|
||||
int32 millis);
|
||||
|
||||
NLSFMTAPI_PUBLIC(int32)
|
||||
NLS_TimeZoneGetRawOffset(const TimeZone* zone);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_TimeZoneSetRawOffset(TimeZone* zone, int32 offset);
|
||||
|
||||
|
||||
/************************ End ******************************/
|
||||
|
||||
NLS_END_PROTOS
|
||||
#endif /* _NLSCAL_H */
|
||||
|
|
@ -0,0 +1,278 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NLSCOL_H
|
||||
#define _NLSCOL_H
|
||||
|
||||
|
||||
#include "nlsxp.h"
|
||||
#include "nlsuni.h"
|
||||
#include "nlsloc.h"
|
||||
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
#include "coll.h"
|
||||
#include "sortkey.h"
|
||||
#endif
|
||||
|
||||
NLS_BEGIN_PROTOS
|
||||
|
||||
/**************************** Types *********************************/
|
||||
|
||||
|
||||
/**
|
||||
* NO_DECOMPOSITION : Accented characters will not be decomposed for sorting.
|
||||
* Please see class description for more details.
|
||||
* CANONICAL_DECOMPOSITION : Characters that are canonical variants according
|
||||
* to Unicode 2.0 will be decomposed for sorting. This is the default setting.
|
||||
* FULL_DECOMPOSITION : Both canonical variants and compatibility variants be
|
||||
* decomposed for sorting.
|
||||
*/
|
||||
|
||||
typedef int NLS_DecompositionMode;
|
||||
enum _NLS_DecompositionMode {
|
||||
NLS_NO_DECOMPOSITION,
|
||||
NLS_CANONICAL_DECOMPOSITION,
|
||||
NLS_FULL_DECOMPOSITION
|
||||
};
|
||||
/**
|
||||
* Base letter represents a primary difference. Set comparison
|
||||
* level to PRIMARY to ignore secondary and tertiary differences.
|
||||
* Use this to set the strength of a collation object.
|
||||
* Example of primary difference, "abc" < "abd"
|
||||
*
|
||||
* Diacritical differences on the same base letter represent a secondary
|
||||
* difference. Set comparison level to SECONDARY to ignore tertiary
|
||||
* differences. Use this to set the strength of a collation object.
|
||||
* Example of secondary difference, "ä" >> "a".
|
||||
*
|
||||
* Uppercase and lowercase versions of the same character represents a
|
||||
* tertiary difference. Set comparison level to TERTIARY to include
|
||||
* all comparison differences. Use this to set the strength of a collation
|
||||
* object.
|
||||
* Example of tertiary difference, "abc" <<< "ABC".
|
||||
*
|
||||
* Two characters are considered "identical" when they are equivalent
|
||||
* unicode spellings.
|
||||
* For example, "ä" == "a¨".
|
||||
*
|
||||
* ECollationStrength is also used to determine the strength of sort keys
|
||||
* generated from Collation objects.
|
||||
*/
|
||||
|
||||
typedef int NLS_CollationStrength;
|
||||
enum _NLS_CollationStrength {
|
||||
NLS_PRIMARY,
|
||||
NLS_SECONDARY,
|
||||
NLS_TERTIARY,
|
||||
NLS_IDENTICAL
|
||||
};
|
||||
/* UnicodeString is the basic type which replaces the char* datatype.
|
||||
- A UnicodeString is an opaque data type, the Unicode String Accessors must be
|
||||
used to access the data.
|
||||
*/
|
||||
#ifndef NLS_CPLUSPLUS
|
||||
typedef struct _Collator Collator; /* depricated names */
|
||||
typedef struct _CollationKey CollationKey;
|
||||
typedef struct _Collation Collation;
|
||||
typedef struct _SortKey SortKey;
|
||||
#endif
|
||||
|
||||
/************************ Library Termination ******************************/
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_ColTerminate(void);
|
||||
|
||||
/************************ Collation Constructor/Destructor ******************************/
|
||||
|
||||
NLSCOLAPI_PUBLIC(const Collator*)
|
||||
NLS_GetDefaultCollation();
|
||||
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewCollation(Collator ** collation, const Locale * locale);
|
||||
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteCollation(Collator * collation);
|
||||
|
||||
/************************ Collation Version ******************************/
|
||||
|
||||
/*
|
||||
Get the major and minor version number from the collation engine.
|
||||
Major version numbers are changed when the collation key and/or sorting for a
|
||||
given locale has changed. The version number is of format 01.00 where
|
||||
the high order number is the Major version number, and the low order
|
||||
number is the minor version number.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(const char*)
|
||||
NLS_GetCollationVersionNumber(Collator *collation);
|
||||
|
||||
/************************ Collation Methods ******************************/
|
||||
|
||||
NLSCOLAPI_PUBLIC(NLS_ComparisonResult)
|
||||
NLS_CollationCompare(const Collator * collation, const UnicodeString * source,
|
||||
const UnicodeString * target);
|
||||
|
||||
NLSCOLAPI_PUBLIC(NLS_ComparisonResult)
|
||||
NLS_CollationCompareRange(const Collator * collation, const UnicodeString * source,
|
||||
TextOffset sourceStart, TextOffset sourceEnd,
|
||||
const UnicodeString * target,
|
||||
TextOffset targetStart, TextOffset targetEnd);
|
||||
|
||||
/** Get a sort key.
|
||||
* key, must be created by the caller using NLS_NewSortKey prior to calling the routine.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CollationGetSortKey(const Collator * collation, const UnicodeString * source,
|
||||
SortKey * key);
|
||||
|
||||
/** Get a sort key.
|
||||
* key, must be created by the caller using NLS_NewSortKey prior to calling the routine.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CollationGetSortKeyUniChar(const Collator * collation, const UniChar * source, size_t length,
|
||||
CollationKey * key);
|
||||
|
||||
|
||||
/** Get a sort key of a specified range.
|
||||
* key, must be created by the caller using NLS_NewSortKey, prior to calling the routine.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CollationGetSortKeyForRange(const Collator * collation, const UnicodeString * source,
|
||||
TextOffset start, TextOffset end, CollationKey * key);
|
||||
|
||||
/** Get a sort key for a non-Unicode encoding.
|
||||
* Key and Collator must be created by caller prior to calling the routine.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CollationGetSortKeyChar(const Collator *collation, const byte* source, size_t length,
|
||||
const char* encoding, CollationKey *key);
|
||||
|
||||
/**
|
||||
* Convenience method for comparing the equality of two strings based on
|
||||
* the collation rules.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(nlsBool)
|
||||
NLS_CollationGreater(const Collator * collation, const UnicodeString * source,
|
||||
const UnicodeString * target);
|
||||
/**
|
||||
* Convenience method for comparing two strings based on the collation
|
||||
* rules.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(nlsBool)
|
||||
NLS_CollationGreaterOrEqual(const Collator * collation, const UnicodeString * source,
|
||||
const UnicodeString * target);
|
||||
/**
|
||||
* Convenience method for comparing two strings based on the collation
|
||||
* rules.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(nlsBool)
|
||||
NLS_CollationEquals(const Collator * collation, const UnicodeString * source,
|
||||
const UnicodeString * target);
|
||||
|
||||
/**
|
||||
* Get the decomposition mode of the collation object.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_DecompositionMode)
|
||||
NLS_CollationGetDecomposition(const Collator * collation);
|
||||
/**
|
||||
* Set the decomposition mode of the collation object.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CollationSetDecomposition(Collator * collation, NLS_DecompositionMode mode);
|
||||
/**
|
||||
* Determines the minimum strength that will be use in comparison or
|
||||
* transformation.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_CollationStrength)
|
||||
NLS_CollationGetStrength(const Collator * collation);
|
||||
/**
|
||||
* Sets the minimum strength to be used in comparison or transformation.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CollationSetStrength(Collator * collation, NLS_CollationStrength newStrength);
|
||||
/**
|
||||
* Get name of the object for the desired Locale, in the desired langauge
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CollationGetDisplayName(const Collator * collation,
|
||||
const Locale * objectLocale,
|
||||
const Locale * displayLocale,
|
||||
UnicodeString * name);
|
||||
/**
|
||||
* Get name of the object for the desired Locale, in the langauge of the
|
||||
* default locale.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CollationGetDefaultDisplayName(const Collator * collation,
|
||||
const Locale * objectLocale,
|
||||
UnicodeString * name);
|
||||
|
||||
|
||||
/************************ SortKey Methods ******************************/
|
||||
|
||||
/**
|
||||
* This creates an empty sort key based on the null string. An empty
|
||||
* sort key contains no sorting information. When comparing two empty
|
||||
* sort keys, the result is EQUAL.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewSortKey(CollationKey ** key);
|
||||
|
||||
/**
|
||||
* Creates a sort key based on the sort key values.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewSortKeyFromValues(CollationKey ** key,
|
||||
const byte * values,
|
||||
size_t count);
|
||||
|
||||
/**
|
||||
* Sort key destructor.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteSortKey(CollationKey *key);
|
||||
|
||||
/**
|
||||
* Compare if two sort keys are the same.
|
||||
* @param source the sort key to compare to.
|
||||
* @return Returns TRUE if two sort keys are equal, FALSE otherwise.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(nlsBool)
|
||||
NLS_SortKeyEqual(const CollationKey * source, const CollationKey * target);
|
||||
|
||||
/**
|
||||
* Extracts the sort key values, the byte array must be pre-allocated
|
||||
* by the caller, and count must specify the number of elements.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(size_t)
|
||||
NLS_GetSortKeyValueLength(const CollationKey * source);
|
||||
|
||||
NLSCOLAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_SortKeyExtractValues(const CollationKey * source, byte * array, size_t count);
|
||||
|
||||
/**
|
||||
* Convenience method which does a string(bit-wise) comparison of the
|
||||
* two sort keys.
|
||||
*/
|
||||
NLSCOLAPI_PUBLIC(NLS_ComparisonResult)
|
||||
NLS_SortKeyCompare(const CollationKey * source, const CollationKey * target);
|
||||
|
||||
|
||||
/************************ End ******************************/
|
||||
NLS_END_PROTOS
|
||||
#endif /* _NLSCOL_H */
|
||||
|
|
@ -0,0 +1,343 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _NLSENC_H
|
||||
#define _NLSENC_H
|
||||
|
||||
|
||||
#include "nlsxp.h"
|
||||
#include "enconv.h"
|
||||
|
||||
NLS_BEGIN_PROTOS
|
||||
|
||||
/********************** Library Initialization ***********************/
|
||||
|
||||
/* NLS_EncInitialize
|
||||
*
|
||||
* Initialize the libcnv library. The dataDirectory is a full or
|
||||
* partial platform specific path specification under which the library may
|
||||
* can find the "converters" sub directories.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_EncInitialize(const NLS_ThreadInfo * threadInfo, const char * dataDirectory);
|
||||
|
||||
/* NLS_EncTerminate
|
||||
*
|
||||
* Terminate the library
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_EncTerminate(void);
|
||||
|
||||
/*********************************************
|
||||
Simple Conversion Routines
|
||||
********************************************/
|
||||
|
||||
/* NLS_EncodingConverterExists
|
||||
*
|
||||
* Tests for the existence of an encoding converter for the source/target
|
||||
* encoding conversion. Encoding names will be normalized by this function
|
||||
* to resolve encoding aliases etc.
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(nlsBool)
|
||||
NLS_EncodingConverterExists(const char *from_charset, const char *to_charset);
|
||||
|
||||
/* NLS_ConvertBuffer
|
||||
*
|
||||
* Converts the source buffer/size to the target buffer/size based on the
|
||||
* source/target encoding information. The encoding names will be normalized
|
||||
* by this function to resolve encoding aliases etc. Use NLS_GetResultBufferSize
|
||||
* to calculate the best output buffer size based on the input encoding.
|
||||
*
|
||||
* Status Returns
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
* NLS_NEW_CONVERTER_FAILED - Function failed
|
||||
* NLS_NO_FROM_ENCODING - No to encoding exists
|
||||
* NLS_NO_TO_ENCODING - No from encoding exists
|
||||
* NLS_NEW_CONVERTER_FAILED - No converter exists
|
||||
*
|
||||
* NLS_RESULT_TRUNCATED - Output buffer was too small,
|
||||
* result was truncated
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_ConvertBuffer(const char *from_charset, const char *to_charset,
|
||||
const byte *inputBuffer, size_t inputBufferLength,
|
||||
byte * outputBuffer, size_t outputBufferLength, size_t * convertedLength);
|
||||
|
||||
/*********************************************
|
||||
Streaming Conversion Routines
|
||||
********************************************/
|
||||
|
||||
/* NLS_NewEncodingConverter
|
||||
*
|
||||
* Create a new encoding converter instance. The encoding names will be normalized
|
||||
* by this function to resolve encoding aliases etc.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
* NLS_NEW_CONVERTER_FAILED - Function failed
|
||||
* NLS_NO_FROM_ENCODING - No to encoding exists
|
||||
* NLS_NO_TO_ENCODING - No from encoding exists
|
||||
* NLS_NEW_CONVERTER_FAILED - No converter exists
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewEncodingConverter(const char *from_charset, const char *to_charset, EncodingConverter** converter);
|
||||
|
||||
/* NLS_DeleteEncodingConverter
|
||||
*
|
||||
* Delete the encoding converter instance.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteEncodingConverter(EncodingConverter * converter);
|
||||
|
||||
|
||||
|
||||
/* NLS_ConvertStreamBuffer
|
||||
*
|
||||
* Converts the source buffer/size to the target buffer/size based on the
|
||||
* source/target encoding information. The encoding names will be normalized
|
||||
* by this function to resolve encoding aliases etc. Use NLS_GetResultBufferSize
|
||||
* to calculate the best output buffer size based on the input encoding.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
* NLS_RESULT_TRUNCATED - Output buffer was too small,
|
||||
* result was truncated
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_ConvertStreamBuffer(EncodingConverter * converter, const byte *inputBuffer, size_t inputBufferLength,
|
||||
byte * outputBuffer, size_t outputBufferLength, size_t * convertedLength);
|
||||
|
||||
/* NLS_GetConversionOverflowSize
|
||||
*
|
||||
* If NLS_ConvertStreamBuffer returned NLS_RESULT_TRUNCATED, the size of the remaining
|
||||
* converted text can be obtained by calling NLS_GetConversionOverflowSize.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_GetConversionOverflowSize(EncodingConverter * converter, size_t * size);
|
||||
|
||||
|
||||
/* NLS_ConverterGetOverflow
|
||||
*
|
||||
* If NLS_ConvertStreamBuffer returned NLS_RESULT_TRUNCATED, the remaining
|
||||
* converted text can be obtained by making consecutive calls to NLS_ConverterGetOverflow.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
* NLS_RESULT_TRUNCATED - Output buffer was too small,
|
||||
* result was truncated
|
||||
*/
|
||||
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_ConverterGetOverflow(EncodingConverter * converter,
|
||||
byte * outputBuffer, size_t outputBufferLength, size_t * convertedLength);
|
||||
|
||||
/* NLS_ResetEncodingConverter
|
||||
*
|
||||
* Resets the converter, clearing any converted and/or unconverted
|
||||
* text from the converter
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_ResetEncodingConverter(EncodingConverter * converter);
|
||||
|
||||
/* NLS_GetConversionRemSize
|
||||
*
|
||||
* When all input text has been converted, there may have been some
|
||||
* characters which did not form a complete convertable group. The number
|
||||
* of remaining bytes can optained by calling NLS_GetConversionRemSize.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_GetConversionRemSize(EncodingConverter * converter, size_t * size);
|
||||
|
||||
/* NLS_GetConversionRem
|
||||
*
|
||||
* When all input text has been converted, there may have been some
|
||||
* characters which did not form a complete convertable group. The
|
||||
* remaining bytes can optained by calling NLS_GetConversionRem.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_GetConversionRem(EncodingConverter * converter, byte * buffer, size_t bufferSize, size_t * size);
|
||||
|
||||
/* NLS_NewEncodingConverterEnumeration
|
||||
*
|
||||
* Create a new encoding converter enumeration instance. The encoding names will be
|
||||
* normalized by this function to resolve encoding aliases etc. One or more of the
|
||||
* encoding names may be spacified as NULL, resulting in all possible convertions being
|
||||
* returned.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
* NLS_NO_FROM_ENCODING - No to encoding exists
|
||||
* NLS_NO_TO_ENCODING - No from encoding exists
|
||||
* NLS_NEW_CONVERTER_LIST_FAILED - No converter exists
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewEncodingConverterEnumeration(const char *from_charset, const char *to_charset,
|
||||
EncondingConverterList ** converterList);
|
||||
|
||||
/* NLS_DeleteEncodingConverterEnumeration
|
||||
*
|
||||
* Delete the encoding converter enumeration instance.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteEncodingConverterEnumeration(EncondingConverterList * converterList);
|
||||
|
||||
/* NLS_CountEncodingConverters
|
||||
*
|
||||
* Get a count of the number of converters that exist.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CountEncodingConverters(EncondingConverterList * converterList, size_t * count);
|
||||
|
||||
/* NLS_GetEncodingConverterListItem
|
||||
*
|
||||
* Caller must supply two char buffers of MAX_ENCODING_NAME_SIZE size, items are
|
||||
* base 0 counted (0-n).
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_GetEncodingConverterListItem(EncondingConverterList * converterList, size_t itemNumber,
|
||||
char *from_charset, char *to_charset);
|
||||
|
||||
/* NLS_GetResultBufferSize
|
||||
*
|
||||
* Returns an estimated buffer size in bytes for the target conversion of the
|
||||
* input stream. The Estimate is garanteed to be larger than the target
|
||||
* conversion will require.
|
||||
*/
|
||||
|
||||
NLSCNVAPI_PUBLIC(size_t)
|
||||
NLS_GetResultBufferSize(const byte *buffer, size_t length,
|
||||
const char *from_charset, const char *to_charset);
|
||||
|
||||
/* NLS_GetNormalizedEncodingName
|
||||
*
|
||||
* Will return the normalized encoding name for known encodings,
|
||||
* eg: UNICODE-1-1-UTF-8 -> UTF-8 etc.
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(const char*)
|
||||
NLS_GetNormalizedEncodingName(const char* encoding);
|
||||
|
||||
/* NLS_GetEncodingNameFromJava
|
||||
*
|
||||
* Will return the normalized encoding name for a known java encoding name.
|
||||
* eg: 8859_1 -> ISO_8859-1:1987 etc.
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(const char*)
|
||||
NLS_GetEncodingNameFromJava(const char* javaName);
|
||||
|
||||
/* NLS_GetJavaEncodingName
|
||||
*
|
||||
* Will return the java encoding name from a normalized encoding name.
|
||||
* eg: ISO_8859-1:1987 -> 8859_1 etc.
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(const char*)
|
||||
NLS_GetJavaEncodingName(const char* encoding);
|
||||
|
||||
/************************ Detection ******************************/
|
||||
|
||||
/* NLS_DetectEncodingForBuffer
|
||||
*
|
||||
* Detects the encoding for a byte buffer, Will cycle through the
|
||||
* known encoding converters trying to auto detect the encoding.
|
||||
* Will create an ordered list of possible encodings for the input
|
||||
* text.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_AUTO_DETECTION_ERROR
|
||||
*/
|
||||
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DetectEncodingForBuffer(const byte *buffer, size_t length,
|
||||
NLS_AUTO_DETECT_RESULT *results, size_t resultsCount, size_t* detectionCount);
|
||||
|
||||
/* NLS_DetectEncodingForUCS2
|
||||
*
|
||||
* Detects the best encoding to convert to from UCS2. Examins the
|
||||
* contents of the UniChar buffer and attempts to find a target
|
||||
* conversion which would generate the least loss.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_AUTO_DETECTION_ERROR
|
||||
*/
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DetectEncodingForUCS2(const UniChar *buffer, size_t length,
|
||||
NLS_AUTO_DETECT_RESULT *results, size_t resultsCount, size_t* detectionCount);
|
||||
|
||||
/* NLS_RegisterStaticLibrary
|
||||
*
|
||||
* Adds registry entries for a statically-linked encoding converter
|
||||
* library to the static link table, making them available for
|
||||
* for creation with standard methods.
|
||||
*
|
||||
* Status Returns
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
|
||||
NLSCNVAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_RegisterStaticLibrary(NLS_StaticConverterRegistry ImportStaticEntryList);
|
||||
/************************ End ******************************/
|
||||
NLS_END_PROTOS
|
||||
#endif /* _NLSENC_H */
|
||||
|
|
@ -0,0 +1,411 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NLSFMT_H
|
||||
#define _NLSFMT_H
|
||||
|
||||
|
||||
#include "nlsxp.h"
|
||||
#include "nlsuni.h"
|
||||
#include "nlsloc.h"
|
||||
#include "nlscal.h"
|
||||
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
#include "format.h"
|
||||
#include "fmtable.h"
|
||||
#include "datefmt.h"
|
||||
#include "numfmt.h"
|
||||
#include "decimfmt.h"
|
||||
#endif
|
||||
|
||||
|
||||
NLS_BEGIN_PROTOS
|
||||
|
||||
/******************** Formatting Data Types ************************/
|
||||
|
||||
#ifndef NLS_CPLUSPLUS
|
||||
typedef struct _Formattable Formattable;
|
||||
typedef struct _DateFormat DateFormat;
|
||||
typedef struct _NumberFormat NumberFormat;
|
||||
typedef struct _DecimalFormat DecimalFormat;
|
||||
typedef struct _DecimalFormatSymbols DecimalFormatSymbols;
|
||||
#endif
|
||||
|
||||
typedef int NLS_FormattableType;
|
||||
enum _NLS_FormattableType {
|
||||
NLS_FORMAT_TYPE_DATE, /* Date */
|
||||
NLS_FORMAT_TYPE_DOUBLE, /* double */
|
||||
NLS_FORMAT_TYPE_LONG, /* long */
|
||||
NLS_FORMAT_TYPE_STRING, /* UnicodeString */
|
||||
NLS_FORMAT_TYPE_ARRAY, /* Formattable[] */
|
||||
NLS_FORMAT_TYPE_CHOICE /* Choice Pattern */
|
||||
};
|
||||
|
||||
|
||||
NLSFMTAPI_PUBLIC(void)
|
||||
NLS_FmtTerminate(void);
|
||||
|
||||
/******************** Simple Formatting functions ************************/
|
||||
|
||||
NLSFMTAPI_PUBLIC(const DateFormat *)
|
||||
NLS_GetDefaultTimeFormat();
|
||||
|
||||
NLSFMTAPI_PUBLIC(const DateFormat *)
|
||||
NLS_GetDefaultDateFormat();
|
||||
|
||||
NLSFMTAPI_PUBLIC(const DateFormat *)
|
||||
NLS_GetDefaultDateTimeFormat();
|
||||
|
||||
NLSFMTAPI_PUBLIC(const NumberFormat *)
|
||||
NLS_GetDefaultNumberFormat();
|
||||
|
||||
NLSFMTAPI_PUBLIC(const NumberFormat *)
|
||||
NLS_GetDefaultCurrencyFormat();
|
||||
|
||||
NLSFMTAPI_PUBLIC(const NumberFormat *)
|
||||
NLS_GetDefaultPercentFormat();
|
||||
|
||||
NLSFMTAPI_PUBLIC(const DecimalFormat *)
|
||||
NLS_GetDefaultDecimalFormat();
|
||||
|
||||
/******************** Formatting Constructor functions ************************/
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewTimeFormat(DateFormat ** result, NLS_DateTimeFormatType style, const Locale* locale);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewDateFormat(DateFormat ** result, NLS_DateTimeFormatType style, const Locale* locale);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewDateTimeFormat(DateFormat ** result, NLS_DateTimeFormatType dateStyle, NLS_DateTimeFormatType timeStyle, const Locale* locale);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewDateFormatCopy(DateFormat ** result, const DateFormat * copyDateFormat);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewNumberFormat(NumberFormat ** result, const Locale* locale);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewNumberFormatCopy(NumberFormat ** result, const NumberFormat * copyNumberFormat);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewCurrencyFormat(NumberFormat ** result, const Locale* locale);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewPercentFormat(NumberFormat ** result, const Locale* locale);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewDecimalFormatSymbols(DecimalFormatSymbols ** result, const Locale* locale);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewDecimalFormatSymbolsCopy(DecimalFormatSymbols ** result, const DecimalFormatSymbols* symbols);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewDecimalFormat(DecimalFormat ** result, const UnicodeString* pattern, const DecimalFormatSymbols* symbols);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewDecimalFormatCopy(DecimalFormat ** result, const DecimalFormat * decimalFormat);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewFormattable(Formattable ** result);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewFormattableFromDate(Formattable ** result, Date date);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewFormattableFromDouble(Formattable ** result, double value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewFormattableFromLong(Formattable ** result, long value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewFormattableFromString(Formattable ** result, const UnicodeString* string);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewFormattableCopy(Formattable ** result, const Formattable * formattable);
|
||||
|
||||
/********************* Formatting Destructor functions *******************************/
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteDateFormat(DateFormat * that);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteNumberFormat(NumberFormat * that);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteDecimalFormat(DecimalFormat * that);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteDecimalFormatSymbols(DecimalFormatSymbols * that);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteFormattable(Formattable * that);
|
||||
|
||||
/******************** Date Formatting API ************************/
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_DateFormatEqual(const DateFormat* format1, const DateFormat* format2);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_FormatDate(const DateFormat* format, Date dateToFormat, UnicodeString* str);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DateFormatParse(const DateFormat* format, const UnicodeString* textToParse, Date *date);
|
||||
|
||||
NLSFMTAPI_PUBLIC(const NumberFormat*)
|
||||
NLS_DateFormatGetNumberFormat(const DateFormat* format);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DateFormatSetNumberFormat(DateFormat* format, const NumberFormat* numberFormat);
|
||||
|
||||
NLSFMTAPI_PUBLIC(const Calendar*)
|
||||
NLS_DateFormatGetCalendar(const DateFormat* format);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DateFormatSetCalendar(DateFormat* format, const Calendar* calendar);
|
||||
|
||||
NLSFMTAPI_PUBLIC(const TimeZone*)
|
||||
NLS_DateFormatGetTimeZone(const DateFormat* format);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DateFormatSetTimeZone(DateFormat* format, const TimeZone* timeZone);
|
||||
|
||||
/******************** Number Formatting API ************************/
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_NumberFormatEquals(const NumberFormat* format1, const NumberFormat* format2);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NumberFormatParse(const NumberFormat* format, const UnicodeString* text, Formattable* result);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NumberFormatDouble(const NumberFormat* format, double number, UnicodeString* result);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NumberFormatLong(const NumberFormat* format, long number, UnicodeString* result);
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_NumberFormatIsParseIntegerOnly(const NumberFormat* format);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NumberFormatSetParseIntegerOnly(NumberFormat* format, nlsBool value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_NumberFormatIsGroupingUsed(const NumberFormat* format);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NumberFormatSetGroupingUsed(NumberFormat* format, nlsBool value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(uint8)
|
||||
NLS_NumberFormatGetMinimumIntegerDigits(const NumberFormat* format);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NumberFormatSetMinimumIntegerDigits(NumberFormat* format, uint8 value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(uint8)
|
||||
NLS_NumberFormatGetMaximumIntegerDigits(const NumberFormat* format);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NumberFormatSetMaximumIntegerDigits(NumberFormat* format, uint8 value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(uint8)
|
||||
NLS_NumberFormatGetMinimumFractionDigits(const NumberFormat* format);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NumberFormatSetMinimumFractionDigits(NumberFormat* format, uint8 value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(uint8)
|
||||
NLS_NumberFormatGetMaximumFractionDigits(const NumberFormat* format);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NumberFormatSetMaximumFractionDigits(NumberFormat* format, uint8 value);
|
||||
|
||||
/******************** Decimal Format Symbols API ************************/
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_DecimalFormatSymbolsEqual(const DecimalFormatSymbols* object, const DecimalFormatSymbols* objectToCompareTo);
|
||||
|
||||
NLSFMTAPI_PUBLIC(UniChar)
|
||||
NLS_DecimalFormatSymbolsGetZeroDigit(const DecimalFormatSymbols* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSymbolsSetZeroDigit(DecimalFormatSymbols* object, UniChar value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(UniChar)
|
||||
NLS_DecimalFormatSymbolsGetGroupingSeparator(const DecimalFormatSymbols* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSymbolsSetGroupingSeparator(DecimalFormatSymbols* object, UniChar value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(UniChar)
|
||||
NLS_DecimalFormatSymbolsGetDecimalSeparator(const DecimalFormatSymbols* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSymbolsSetDecimalSeparator(DecimalFormatSymbols* object, UniChar value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(UniChar)
|
||||
NLS_DecimalFormatSymbolsGetPerMill(const DecimalFormatSymbols* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSymbolsSetPerMill(DecimalFormatSymbols* object, UniChar value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(UniChar)
|
||||
NLS_DecimalFormatSymbolsGetPercent(const DecimalFormatSymbols* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSymbolsSetPercent(DecimalFormatSymbols* object, UniChar value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(UniChar)
|
||||
NLS_DecimalFormatSymbolsGetDigit(const DecimalFormatSymbols* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSymbolsSetDigit(DecimalFormatSymbols* object, UniChar value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(UniChar)
|
||||
NLS_DecimalFormatSymbolsGetMinusSign(const DecimalFormatSymbols* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSymbolsSetMinusSign(DecimalFormatSymbols* object, UniChar value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(UniChar)
|
||||
NLS_DecimalFormatSymbolsGetExponential(const DecimalFormatSymbols* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSymbolsSetExponential(DecimalFormatSymbols* object, UniChar value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(UniChar)
|
||||
NLS_DecimalFormatSymbolsGetPatternSeparator(const DecimalFormatSymbols* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSymbolsSetPatternSeparator(DecimalFormatSymbols* object, UniChar value);
|
||||
|
||||
/******************** Decimal Formatting API ************************/
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_DecimalFormatEqual(const DecimalFormat* object, const DecimalFormat* objectToCompareTo);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatDouble(const DecimalFormat* object, double number, UnicodeString* toAppendTo);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatLong(const DecimalFormat* object, long number, UnicodeString* toAppendTo);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatParse(const DecimalFormat* object, const UnicodeString* text, Formattable* result);
|
||||
|
||||
NLSFMTAPI_PUBLIC(const DecimalFormatSymbols*)
|
||||
NLS_DecimalFormatGetDecimalFormatSymbols(const DecimalFormat* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSetDecimalFormatSymbols(DecimalFormat* object, const DecimalFormatSymbols* symbolsToAdopt);
|
||||
|
||||
NLSFMTAPI_PUBLIC(const UnicodeString*)
|
||||
NLS_DecimalFormatGetPositivePrefix(const DecimalFormat* object, UnicodeString* result);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSetPositivePrefix(DecimalFormat* object, const UnicodeString* value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(const UnicodeString*)
|
||||
NLS_DecimalFormatGetNegativePrefix(const DecimalFormat* object, UnicodeString* result);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSetNegativePrefix(DecimalFormat* object, const UnicodeString* value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(const UnicodeString*)
|
||||
NLS_DecimalFormatGetPositiveSuffix(const DecimalFormat* object, UnicodeString* result);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSetPositiveSuffix(DecimalFormat* object, const UnicodeString* value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(const UnicodeString*)
|
||||
NLS_DecimalFormatGetNegativeSuffix(const DecimalFormat* object, UnicodeString* result);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSetNegativeSuffix(DecimalFormat* object, const UnicodeString* value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(int32)
|
||||
NLS_DecimalFormatGetMultiplier(const DecimalFormat* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSetMultiplier(DecimalFormat* object, int32 multiplier);
|
||||
|
||||
NLSFMTAPI_PUBLIC(uint8)
|
||||
NLS_DecimalFormatGetGroupingSize(const DecimalFormat* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSetGroupingSize(DecimalFormat* object, uint8 groupingSize);
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_DecimalFormatGetDecimalSeparatorAlwaysShown(const DecimalFormat* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSetDecimalSeparatorAlwaysShown(DecimalFormat* object, nlsBool alwaysShown);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatGetPattern(const DecimalFormat* object, UnicodeString* value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSetPattern(DecimalFormat* object, const UnicodeString* value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatGetLocalizedPattern(const DecimalFormat* object, UnicodeString* value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DecimalFormatSetLocalizedPattern(DecimalFormat* object, const UnicodeString* value);
|
||||
|
||||
|
||||
/******************** Formattable API ************************/
|
||||
|
||||
NLSFMTAPI_PUBLIC(nlsBool)
|
||||
NLS_FormattableEqual(const Formattable* object, const Formattable* objectToCompareTo);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_FormattableType)
|
||||
NLS_FormattableGetType(const Formattable* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(double)
|
||||
NLS_FormattableGetDouble(const Formattable* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(long)
|
||||
NLS_FormattableGetLong(const Formattable* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(Date)
|
||||
NLS_FormattableGetDate(const Formattable* object);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_FormattableGetString(const Formattable* object, UnicodeString* result);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_FormattableSetDouble(Formattable* object, double value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_FormattableSetLong(Formattable* object, long value);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_FormattableSetDate(Formattable* object, Date date);
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_FormattableSetString(Formattable* object, const UnicodeString* stringToCopy);
|
||||
|
||||
|
||||
|
||||
/************************ End ******************************/
|
||||
|
||||
NLS_END_PROTOS
|
||||
#endif /* _NLSFMT_H */
|
||||
|
|
@ -0,0 +1,395 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NLSLOC_H
|
||||
#define _NLSLOC_H
|
||||
|
||||
|
||||
#include "nlsxp.h"
|
||||
#include "nlsuni.h"
|
||||
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
#include "locid.h"
|
||||
#endif
|
||||
|
||||
NLS_BEGIN_PROTOS
|
||||
|
||||
/**************************** Types *********************************/
|
||||
|
||||
|
||||
|
||||
/* UnicodeString is the basic type which replaces the char* datatype.
|
||||
- A UnicodeString is an opaque data type, the Unicode String Accessors must be
|
||||
used to access the data.
|
||||
*/
|
||||
#ifndef NLS_CPLUSPLUS
|
||||
typedef struct _Locale Locale;
|
||||
#endif
|
||||
|
||||
/********************** Library Initialization ***********************/
|
||||
|
||||
|
||||
/* NLS_Initialize
|
||||
*
|
||||
* Initialize the libuni library. If the application is a multi-threaded
|
||||
* application is should supply a threadInfo specification to allow
|
||||
* the library to protect critical code sections. The dataDirectory is a full or
|
||||
* partial platform specific path specification under which the library may
|
||||
* can find the "locales" and "converters" sub directories.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_Initialize(const NLS_ThreadInfo * threadInfo, const char * dataDirectory);
|
||||
|
||||
/* NLS_Terminate
|
||||
*
|
||||
* Terminate the library
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_Terminate(void);
|
||||
|
||||
/************************ Locale Methods ******************************/
|
||||
|
||||
/** NLS_GetDefaultLocale
|
||||
*
|
||||
* Returns the default locale setting. The default locale is based on
|
||||
* the platform locale setting.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(const Locale *)
|
||||
NLS_GetDefaultLocale();
|
||||
|
||||
/** NLS_SetDefaultLocale
|
||||
*
|
||||
* Sets the default.
|
||||
* Normally set once at the beginning of the application,
|
||||
* then never reset. setDefault does not reset the host locale.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_SetDefaultLocale(const Locale * locale);
|
||||
|
||||
|
||||
/** NLS_NewNamedLocale
|
||||
*
|
||||
* Construct a locale from language, country, variant. Any or all of the
|
||||
* UnicodeStrings may be NULL.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_NEW_LOCALE_FAILED
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewNamedLocale(Locale ** locale,
|
||||
const UnicodeString * language,
|
||||
const UnicodeString * country,
|
||||
const UnicodeString * variant);
|
||||
|
||||
/** NLS_NewNamedLocaleFromChar
|
||||
*
|
||||
* Construct a locale from language, country, variant. Any or all of the
|
||||
* char* may be NULL.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_NEW_LOCALE_FAILED
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewNamedLocaleFromChar(Locale ** locale,
|
||||
const char * language,
|
||||
const char * country,
|
||||
const char * variant);
|
||||
|
||||
/** NLS_NewNamedLocaleFromLocaleSpec
|
||||
*
|
||||
* Construct a locale from a localeSpec of the form "en_US_variant"
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_NEW_LOCALE_FAILED
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewNamedLocaleFromLocaleSpec(Locale ** locale,
|
||||
const char * localeSpec);
|
||||
|
||||
|
||||
/** NLS_DeleteLocale
|
||||
*
|
||||
* Destroy a locale
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteLocale(Locale *locale);
|
||||
|
||||
/** NLS_EqualLocales
|
||||
*
|
||||
* Equality test for locales
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_EqualLocales(const Locale * source, const Locale * target);
|
||||
|
||||
/** NLS_LocaleGetLanguage
|
||||
*
|
||||
* Getter for programmatic name of field,
|
||||
* an lowercased two-letter ISO-639 code.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetLanguage(const Locale * locale, UnicodeString * lang);
|
||||
|
||||
/** NLS_LocaleGetCountry
|
||||
*
|
||||
* Getter for programmatic name of field,
|
||||
* an uppercased two-letter ISO-3166 code.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetCountry(const Locale * locale, UnicodeString * cntry);
|
||||
|
||||
/** NLS_LocaleGetVariant
|
||||
*
|
||||
* Getter for programmatic name of field.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetVariant(const Locale * locale, UnicodeString * var);
|
||||
|
||||
/** NLS_LocaleGetName
|
||||
*
|
||||
* Getter for the programmatic name of the entire locale,
|
||||
* with the language, country and variant separated by underbars.
|
||||
* If a field is missing, at most one underbar will occur.
|
||||
* Example: "en", "de_DE", "en_US_WIN", "de_POSIX", "fr_MAC"
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetName(const Locale * locale, UnicodeString * name);
|
||||
|
||||
/** NLS_LocaleGetISO3Language
|
||||
*
|
||||
* Getter for the three-letter ISO language abbreviation
|
||||
* of the locale.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetISO3Language(const Locale * locale, UnicodeString * name);
|
||||
|
||||
/** NLS_LocaleGetISO3Country
|
||||
*
|
||||
* Getter for the three-letter ISO country abbreviation
|
||||
* of the locale.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetISO3Country(const Locale * locale, UnicodeString * name);
|
||||
|
||||
/** NLS_LocaleGetDisplayLanguage
|
||||
*
|
||||
* Getter for display of field to user.
|
||||
* If the localized name is not found, returns the ISO code.
|
||||
* The desired user language is from the default locale.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetDisplayLanguage(const Locale * locale, UnicodeString * dispLang);
|
||||
|
||||
/** NLS_LocaleGetDisplayLanguageInLocale
|
||||
*
|
||||
* Getter for display of field to user.
|
||||
* If the localized name is not found, returns the ISO codes.
|
||||
* Example: "English (UK)", "Deutch", "Germany"
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetDisplayLanguageInLocale(const Locale * locale,
|
||||
const Locale * inLocale, UnicodeString * dispLang);
|
||||
|
||||
/** NLS_LocaleGetDisplayCountry
|
||||
*
|
||||
* Getter for display of field to user.
|
||||
* If the localized name is not found, returns the ISO code.
|
||||
* The default locale is used for the presentation language.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetDisplayCountry(const Locale * locale,
|
||||
UnicodeString * dispCountry);
|
||||
|
||||
/** NLS_LocaleGetDisplayCountryInLocale
|
||||
*
|
||||
* Getter for display of field to user.
|
||||
* If the localized name is not found, returns the ISO code.
|
||||
* @param inLocale specifies the desired user language.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetDisplayCountryInLocale(const Locale * locale,
|
||||
const Locale * inLocale, UnicodeString * dispCountry);
|
||||
|
||||
/** NLS_LocaleGetDisplayVariant
|
||||
*
|
||||
* Getter for display of field to user.
|
||||
* If the localized name is not found, returns the variant code.
|
||||
* The default locale is used for the presentation language.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetDisplayVariant(const Locale * locale, UnicodeString * dispVar);
|
||||
|
||||
/** NLS_LocaleGetDisplayVariantInLocale
|
||||
*
|
||||
* Getter for display of field to user
|
||||
* If the localized name is not found, returns the variant code.
|
||||
* @param inLocale specifies the desired user language.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetDisplayVariantInLocale(const Locale * locale,
|
||||
const Locale * inLocale, UnicodeString * dispVar) ;
|
||||
|
||||
/** NLS_LocaleGetDisplayName
|
||||
*
|
||||
* Getter for display of the entire locale to user.
|
||||
* If the localized name is not found, uses the ISO codes.
|
||||
* The default locale is used for the presentation language.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetDisplayName(const Locale * locale, UnicodeString * name);
|
||||
|
||||
/** NLS_LocaleGetDisplayNameInLocale
|
||||
*
|
||||
* Getter for display of the entire locale to user.
|
||||
* If the localized name is not found, uses the ISO codes
|
||||
* @param inLocale specifies the desired user language.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetDisplayNameInLocale(const Locale * locale,
|
||||
const Locale * inLocale, UnicodeString * name);
|
||||
|
||||
/** NLS_LocaleCountAvailableLocales
|
||||
*
|
||||
* Get the count of the set of Locales are installed
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(size_t)
|
||||
NLS_LocaleCountAvailableLocales();
|
||||
|
||||
/** NLS_LocaleGetAvailableLocales
|
||||
*
|
||||
* Get the set of Locales for which, the array must be
|
||||
* allocated by the caller, and count must specify how many entries exist.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_LocaleGetAvailableLocales(Locale * LocaleArray,
|
||||
size_t inCount,
|
||||
size_t *count);
|
||||
|
||||
/********************* UnicodeString Accessor functions *******************************/
|
||||
|
||||
|
||||
/** NLS_LocaleGetAvailableLocales
|
||||
*
|
||||
* Upper case a string according to specific Locale rules
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringtoUpperForLocale(UnicodeString * target, const Locale * locale);
|
||||
|
||||
/** NLS_UnicodeStringtoLowerForLocale
|
||||
*
|
||||
* Lower case a string according to specific Locale rules
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringtoLowerForLocale(UnicodeString * target, const Locale * locale);
|
||||
|
||||
|
||||
/************************ End ******************************/
|
||||
NLS_END_PROTOS
|
||||
#endif /* _NLSLOC_H */
|
||||
|
|
@ -0,0 +1,145 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NLSMSG_H
|
||||
#define _NLSMSG_H
|
||||
|
||||
|
||||
#include "nlsxp.h"
|
||||
#include "nlsuni.h"
|
||||
#include "nlsfmt.h"
|
||||
#include "nlsloc.h"
|
||||
#include "nlscal.h"
|
||||
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
#include "fmtable.h"
|
||||
#include "choicfmt.h"
|
||||
#include "msgfmt.h"
|
||||
#endif
|
||||
|
||||
|
||||
NLS_BEGIN_PROTOS
|
||||
|
||||
/******************** Formatting Data Types ************************/
|
||||
|
||||
#ifndef NLS_CPLUSPLUS
|
||||
typedef struct _MessageFormat MessageFormat;
|
||||
#endif
|
||||
|
||||
/******************** Simple Formatting functions ************************/
|
||||
|
||||
/* NLS_FormatMessage
|
||||
*
|
||||
* varg simple message formatting.
|
||||
* varg's are value pairs composed of NLS_FormattableType followed by
|
||||
* argument. The last parameter to the routine should be -1 to indicate the
|
||||
* end of the parameters.
|
||||
* eg:
|
||||
*
|
||||
* err = NLS_FormatMessage(result,
|
||||
* "There {0,choice,0#are no files|1#is one file|1<are {0,number} files}.",
|
||||
* NLS_TYPE_STRING, "A Disk",
|
||||
* NLS_TYPE_LONG, 5, -1);
|
||||
*/
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_FormatMessage(const Locale *locale, UnicodeString *result, const UnicodeString* pattern, ...);
|
||||
|
||||
|
||||
/******************** Formatting Constructor functions ************************/
|
||||
|
||||
/* NLS_NewMessageFormat
|
||||
*
|
||||
* Create a MessageFormat from a pattern. The patern is a choice format
|
||||
* specification of the form
|
||||
*
|
||||
* "There {0,choice,0#are no files|1#is one file|1<are {0,number} files}."
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewMessageFormat(const Locale *locale, MessageFormat ** result, const UnicodeString* pattern);
|
||||
|
||||
/********************* Formatting Destructor functions *******************************/
|
||||
|
||||
/* NLS_DeleteMessageFormat
|
||||
*
|
||||
* Delete a MessageFormat object.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteMessageFormat(MessageFormat * that);
|
||||
|
||||
/******************** Formatting API ************************/
|
||||
|
||||
/* NLS_MessageFormatSetPattern
|
||||
*
|
||||
* Change the patter associated with the MessageFormat object
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_MessageFormatSetPattern(MessageFormat * that, const UnicodeString* pattern);
|
||||
|
||||
/* NLS_MessageFormatGetPattern
|
||||
*
|
||||
* Get the pattern associated with a choice format object
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_MessageFormatGetPattern(MessageFormat * that, UnicodeString* pattern);
|
||||
|
||||
/* NLS_MessageFormat
|
||||
*
|
||||
* Generate a formatted string using the pattern associated
|
||||
* with the choice format, based on the specified parameters
|
||||
*
|
||||
* varg's are value pairs composed of NLS_FormattableType followed by
|
||||
* argument. The last parameter to the routine should be -1 to indicate the
|
||||
* end of the parameters.
|
||||
* eg:
|
||||
*
|
||||
* err = NLS_MessageFormat(MessageFormat, result,
|
||||
* NLS_TYPE_STRING, "A Disk",
|
||||
* NLS_TYPE_LONG, 5, -1);
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR - parameter verification failed
|
||||
*/
|
||||
|
||||
NLSFMTAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_MessageFormat(const MessageFormat * that, UnicodeString* result, ...);
|
||||
|
||||
|
||||
/************************ End ******************************/
|
||||
|
||||
NLS_END_PROTOS
|
||||
#endif /* _NLSMSG_H */
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NLSPRIV_H
|
||||
#define _NLSPRIV_H
|
||||
|
||||
#include "nlsxp.h"
|
||||
|
||||
#ifdef NLS_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
// Resource reference
|
||||
*/
|
||||
#ifdef NLS_WIN
|
||||
typedef HMODULE NLS_ResModuleRef;
|
||||
#elif defined(NLS_MAC)
|
||||
typedef short NLS_ResModuleRef;
|
||||
#else
|
||||
typedef uint32 NLS_ResModuleRef;
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,140 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef PRSXP_H_
|
||||
#define PRSXP_H_
|
||||
|
||||
#include "nlsxp.h"
|
||||
#include "unistring.h"
|
||||
|
||||
#ifndef nil
|
||||
#define nil 0
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* flush out all the system macros */
|
||||
#if defined(macintosh) || defined(__MWERKS__) || defined(applec)
|
||||
#ifndef PRS_MAC
|
||||
#define PRS_MAC
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__unix) || defined(unix) || defined(UNIX) || defined(XP_UNIX)
|
||||
#ifndef PRS_UNIX
|
||||
#define PRS_UNIX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_WINDOWS) || defined(XP_PC) || defined(_CONSOLE)
|
||||
#ifndef PRS_PC
|
||||
#define PRS_PC
|
||||
#endif /* ifndef PRS_PC */
|
||||
#endif
|
||||
|
||||
#if !defined(PRS_MAC) && !defined(PRS_UNIX) && !defined(PRS_PC)
|
||||
#error "libPRS can not determine system type"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* X-platform stuff */
|
||||
#ifdef PRS_MAC
|
||||
#define PRS_DEFSET_INCOMING NLS_ENCODING_MAC_ROMAN
|
||||
#define PRS_DEFSET_INCOMING NLS_ENCODING_MAC_ROMAN
|
||||
#define PRS_NEWLINE UnicodeString("\n")
|
||||
#define PRS_DIRECTORY_SEPARATOR '/'
|
||||
#define PRS_DIRECTORY_SEPARATOR_STR "/"
|
||||
#else
|
||||
#define PRS_DEFSET_INCOMING NLS_ENCODING_ISO_8859_1
|
||||
#endif
|
||||
|
||||
#ifdef PRS_PC
|
||||
#define PRS_NEWLINE UnicodeString("\n")
|
||||
#define PRS_DIRECTORY_SEPARATOR '\\'
|
||||
#define PRS_DIRECTORY_SEPARATOR_STR "\\"
|
||||
#endif
|
||||
|
||||
#ifdef PRS_UNIX
|
||||
#define PRS_NEWLINE UnicodeString("\n")
|
||||
#define PRS_DIRECTORY_SEPARATOR '/'
|
||||
#define PRS_DIRECTORY_SEPARATOR_STR "/"
|
||||
#endif
|
||||
|
||||
#define PRS_DEFSET_EXPORT NLS_ENCODING_UTF_8
|
||||
#define PRS_DEFSET_RESOURCE NLS_ENCODING_ESCAPED_UNICODE
|
||||
#define PRS_DEFSET_OUTGOING PRS_DEFSET_INCOMING
|
||||
|
||||
#define PRS_EXPORT_SUFFIX ".export"
|
||||
#define PRS_RESOURCE_SUFFIX ".properties"
|
||||
|
||||
#define PRS_MAX_RESOURCE_NAME_LENGTH 132
|
||||
|
||||
#define PRS_RESOURCE_DELIMETER UnicodeString("=")
|
||||
#define PRS_RESOURCE_DELIMETER_CHAR '='
|
||||
#define PRS_ID_UNKNOWN 0x0000
|
||||
#define PRS_ID_STRING 0x0101 // Any text not within a tag. Delimeted by tags on either side.
|
||||
#define PRS_ID_TAG 0x0102 // An HTML Tag. Delimited by < >.
|
||||
#define PRS_ID_SUBSTRING 0x0103 // A quoted string occuring within a tag or Javascript.
|
||||
struct PRS_ErrorPair { int code; char *message; };
|
||||
typedef PRS_ErrorPair *PRS_ErrorCode;
|
||||
|
||||
|
||||
// #define PRS_NEWLINE "\r\n"
|
||||
// #define PRS_NEWLINE_LENGTH 2
|
||||
#define PRS_WHITESPACE UnicodeString(" ")
|
||||
// #define PRS_WHITESPACE_LENGTH 1
|
||||
|
||||
#define PRS_REGISTRY_DEFAULT_HASHSIZE 91
|
||||
|
||||
#define PRS_EOF 0xFFFF
|
||||
|
||||
#define isWhite(x) (((x) == 13) || ((x) == 10) || ((x) == ' ') || ((x) == ' '))
|
||||
#define isNewline(x) (((x) == 13) || ((x) == 10))
|
||||
#define isTagStart(x) ((x) == '<')
|
||||
#define isTagEnd(x) ((x) == '>')
|
||||
#define isResourceDelimeter(x) ((x) == PRS_RESOURCE_DELIMETER_CHAR)
|
||||
|
||||
extern PRS_ErrorCode PRS_SUCCESS;
|
||||
extern PRS_ErrorCode PRS_RESERVED;
|
||||
extern PRS_ErrorCode PRS_FAIL;
|
||||
extern PRS_ErrorCode PRS_OUT_OF_MEMORY;
|
||||
extern PRS_ErrorCode PRS_FILE_WRITE_ERROR;
|
||||
extern PRS_ErrorCode PRS_FILE_READ_ERROR;
|
||||
extern PRS_ErrorCode PRS_BAD_PARAMETER;
|
||||
extern PRS_ErrorCode PRS_FILE_NOT_FOUND;
|
||||
extern PRS_ErrorCode PRS_FILE_CREATE_ERROR;
|
||||
extern PRS_ErrorCode PRS_FILE_CLOSE_ERROR;
|
||||
extern PRS_ErrorCode PRS_PARSE_ERROR;
|
||||
extern PRS_ErrorCode PRS_PARSE_ERROR_TAG;
|
||||
extern PRS_ErrorCode PRS_PARSE_ERROR_QUOTE;
|
||||
extern PRS_ErrorCode PRS_RES_FORMAT_EXCEPTION;
|
||||
|
||||
|
||||
#endif // !defined(PRSXP_H_)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,330 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NLSRES_H
|
||||
#define _NLSRES_H
|
||||
|
||||
#include "nlsxp.h"
|
||||
|
||||
#include "nlsuni.h"
|
||||
#include "nlsloc.h"
|
||||
#include "nlsmsg.h"
|
||||
#include "nlsutl.h"
|
||||
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
#include "resbdl.h"
|
||||
#include "msgfmt.h"
|
||||
#include "msgstr.h"
|
||||
#endif
|
||||
|
||||
NLS_BEGIN_PROTOS
|
||||
|
||||
/**************************** Types *********************************/
|
||||
|
||||
#ifndef NLS_CPLUSPLUS
|
||||
typedef struct _PropertyResourceBundle PropertyResourceBundle;
|
||||
typedef struct _MessageString MessageString;
|
||||
#endif
|
||||
|
||||
/********************** Library Initialization ***********************/
|
||||
|
||||
|
||||
/* NLS_ResInitialize
|
||||
*
|
||||
* Initialize the NLS Resource library.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_ResInitialize(const NLS_ThreadInfo* threadInfo, const char* resourceDirectory);
|
||||
|
||||
/* NLS_ResTerminate
|
||||
*
|
||||
* Terminate the library.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_ResTerminate(void);
|
||||
|
||||
/************************ Search Path APIs ******************************/
|
||||
|
||||
/* NLS_ResAddSearchPath
|
||||
*
|
||||
* Add a new search path to the NLS Resource library for
|
||||
* searching for resource files
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCES - completed
|
||||
* NLS_PARAM_ERROR - bad search path
|
||||
* NLS_INTERNAL_PROGRAM_ERROR - internal failure, could not add path
|
||||
*
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_ResAddSearchPath(const char* searchPath);
|
||||
|
||||
/* NLS_GetSearchPath
|
||||
*
|
||||
* Returns the current search path as a const char*
|
||||
*
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(const char*)
|
||||
NLS_ResGetSearchPath(void);
|
||||
|
||||
|
||||
/************************ Simple Resource APIs ******************************/
|
||||
|
||||
/** NLS_PropertyResourceGetUnicodeResource
|
||||
*
|
||||
* Gets a UnioceString resource from the specified property file, given the user accept-language
|
||||
* specification. The UnicodeString must be release by call NLS_DeleteUnicodeString
|
||||
*
|
||||
* Status Return
|
||||
* If the resource is not located a NULL pointer will return.
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(UnicodeString*)
|
||||
NLS_PropertyResourceGetUnicodeResource(const char* packageName, const char* acceptLanguage,
|
||||
const char* key);
|
||||
|
||||
/** NLS_PropertyResourceGetCharResource
|
||||
*
|
||||
* Gets a char* resource from the specified property file, given the user accept-language
|
||||
* specification in the specified encoding.
|
||||
* If the to_charset is not specified, the property $TARGET_ENCODING$ in the resouce
|
||||
* bundle will be used to specify the encoding. The cvhar* must be release by call free()
|
||||
*
|
||||
* Status Return
|
||||
* If the resource is not located a NULL pointer will return.
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(char*)
|
||||
NLS_PropertyResourceGetCharResource(const char* packageName, const char* acceptLanguage,
|
||||
const char* key, const char* to_charset);
|
||||
|
||||
|
||||
|
||||
/************************ Resource APIs ******************************/
|
||||
|
||||
/** NLS_PropertyResourceBundleExists
|
||||
*
|
||||
* Determine if the specified resource bundle (or something close to it) exists.
|
||||
*
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(nlsBool)
|
||||
NLS_PropertyResourceBundleExists(const char* packageName,
|
||||
const Locale* locale);
|
||||
|
||||
/** NLS_NewPropertyResourceBundle
|
||||
*
|
||||
* Creates a new PropertyResourceBundle from the specified locale and
|
||||
* package name.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_USING_FALLBACK_LOCALE
|
||||
* NLS_PARAM_ERROR
|
||||
* NLS_RESOURCE_OPEN_ERROR
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewPropertyResourceBundle(PropertyResourceBundle** resourceBundle,
|
||||
const char* packageName,
|
||||
const Locale* locale);
|
||||
|
||||
/** NLS_NewPropertyResourceBundleFromAcceptLanguage
|
||||
*
|
||||
* Creates a new PropertyResourceBundle from the specified accept-language string and
|
||||
* package name.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_USING_FALLBACK_LOCALE
|
||||
* NLS_PARAM_ERROR
|
||||
* NLS_RESOURCE_OPEN_ERROR
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewPropertyResourceBundleFromAcceptLanguage(PropertyResourceBundle** resourceBundle,
|
||||
const char* packageName,
|
||||
const char* acceptLanguage);
|
||||
|
||||
/** NLS_DeletePropertyResourceBundle
|
||||
*
|
||||
* Destroy a ResourceBundle.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeletePropertyResourceBundle(PropertyResourceBundle* resourceBundle);
|
||||
|
||||
|
||||
/** NLS_PropertyResourceBundleGetString
|
||||
*
|
||||
* Get a string from the ResourceBundle given a key.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
* NLS_RESOURCE_NOT_FOUND
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_PropertyResourceBundleGetString(PropertyResourceBundle* resourceBundle,
|
||||
const char* key, UnicodeString * resource);
|
||||
|
||||
/** NLS_PropertyResourceBundleGetStringUniChar
|
||||
*
|
||||
* Get a string from the ResourceBundle, lengths are UniChar counts, and
|
||||
* not byte counts.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
* NLS_RESOURCE_NOT_FOUND
|
||||
* NLS_RESULT_TRUNCATED
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_PropertyResourceBundleGetStringUniChar(PropertyResourceBundle* resourceBundle,
|
||||
const char* key,
|
||||
UniChar* resource,
|
||||
size_t length,
|
||||
size_t* resultLength);
|
||||
|
||||
/** NLS_PropertyResourceBundleGetChar
|
||||
*
|
||||
* Get a char* from the ResourceBundle. The memory allocated by this routine must
|
||||
* be freed using free(); If no encoding name is specified the routine will use the
|
||||
* default encoding specified by the property file itself to specify the output encoding.
|
||||
*
|
||||
* Status Return
|
||||
* If an error occurs, a NULL pointer will be returned by this routine.
|
||||
*
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(char*)
|
||||
NLS_PropertyResourceBundleGetChar(PropertyResourceBundle* resourceBundle,
|
||||
const char* key,
|
||||
const char* to_charset);
|
||||
|
||||
/** NLS_PropertyResourceBundleGetStringLength
|
||||
*
|
||||
* Get the UniChar length from the string corresponding to the key passed in.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
* NLS_RESOURCE_NOT_FOUND
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_PropertyResourceBundleGetStringLength(PropertyResourceBundle *resourceBundle,
|
||||
const char* key,
|
||||
size_t *resultLength);
|
||||
|
||||
|
||||
/************************ Message String ******************************/
|
||||
|
||||
/** NLS_NewMessageString
|
||||
*
|
||||
* Creates a new MessageString. A message string is a packed formatted message
|
||||
* which includes the message key, and the parameters. A string representation
|
||||
* for the message string can be obtained in any locale.
|
||||
*
|
||||
* err = NLS_NewMessageString(result,
|
||||
* "my.package.string", "STRING_1",
|
||||
* NLS_TYPE_STRING, "A Disk",
|
||||
* NLS_TYPE_LONG, 5, -1);
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewMessageString(MessageString** messageString,
|
||||
const char* packageName,
|
||||
const char* key, ...);
|
||||
|
||||
/** NLS_NewMessageStringFromTemplate
|
||||
*
|
||||
* Creates a new MessageString. From the exported format.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewMessageStringFromExportFormat(MessageString** messageString,
|
||||
const char* exportFormat);
|
||||
|
||||
/** NLS_DeleteMessageString
|
||||
*
|
||||
* Destroy a ResourceBundle.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteMessageString(MessageString* messageString);
|
||||
|
||||
|
||||
/** NLS_MessageStringGetExportFormat
|
||||
*
|
||||
* Gets an exportable format string from the MessageString. This can be used to
|
||||
* recreade a MessageString at some future point in time.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
* NLS_RESULT_TRUNCATED
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(const char*)
|
||||
NLS_MessageStringGetExportFormat(MessageString *messageString);
|
||||
|
||||
/** NLS_MessageStringGetStringFromLocale
|
||||
*
|
||||
* Gets the user visible string from the MessageString for a given locale.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
* NLS_RESOURCE_NOT_FOUND
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_MessageStringGetStringFromLocale(MessageString *messageString,
|
||||
const Locale* locale,
|
||||
UnicodeString * resource);
|
||||
|
||||
/** NLS_MessageStringGetStringFromLocale
|
||||
*
|
||||
* Gets the user visible string from the MessageString for a given accept-language.
|
||||
*
|
||||
* Status Return
|
||||
* NLS_SUCCESS
|
||||
* NLS_PARAM_ERROR
|
||||
* NLS_RESOURCE_NOT_FOUND
|
||||
*/
|
||||
NLSRESAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_MessageStringGetStringFromAcceptLanguage(MessageString *messageString,
|
||||
const char* acceptLanguage,
|
||||
UnicodeString * resource);
|
||||
|
||||
|
||||
/************************ End ******************************/
|
||||
NLS_END_PROTOS
|
||||
#endif /* _NLSRES_H */
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NLSTXB_H
|
||||
#define _NLSTXB_H
|
||||
|
||||
|
||||
#include "nlsxp.h"
|
||||
#include "nlsuni.h"
|
||||
#include "nlsloc.h"
|
||||
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
#include "txtbdry.h"
|
||||
#endif
|
||||
|
||||
|
||||
NLS_BEGIN_PROTOS
|
||||
|
||||
/******************** TextBoundary Data Types ************************/
|
||||
|
||||
#ifndef NLS_CPLUSPLUS
|
||||
typedef struct _TextBoundary TextBoundary;
|
||||
#endif
|
||||
|
||||
enum _NLS_TextBoundaryDone {
|
||||
NLS_TextBoundaryDone = (TextOffset)-1L
|
||||
};
|
||||
|
||||
/******************** TextBoundary Constructor functions ************************/
|
||||
|
||||
/**
|
||||
* Create a Character Break Text Boundry for the given locale
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewCharacterTextBoundary(TextBoundary ** result,
|
||||
const Locale* locale);
|
||||
|
||||
/**
|
||||
* Create a Word break text boundry for the given locale.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewWordTextBoundary(TextBoundary ** result,
|
||||
const Locale* locale);
|
||||
|
||||
/**
|
||||
* Create a Line Break Text Boundry for the given locale
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewLineTextBoundary(TextBoundary ** result,
|
||||
const Locale* locale);
|
||||
|
||||
/**
|
||||
* Create a Sentence Break Text Boundry for the given locale
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewSentenceTextBoundary(TextBoundary ** result,
|
||||
const Locale* locale);
|
||||
|
||||
/********************* TextBoundary Destructor functions *******************************/
|
||||
|
||||
/* Destructor for an TextBoundary */
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteTextBoundary(TextBoundary * that);
|
||||
|
||||
/******************** TextBoundary API ************************/
|
||||
|
||||
/**
|
||||
* Set the text for the text boundry object. Replaces any text
|
||||
* that may be set, and resets the state of the text boundry
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_TextBoundarySetText(TextBoundary * that,
|
||||
const UnicodeString* text);
|
||||
|
||||
/**
|
||||
* Gets the text that is currently set on the text boundry.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(const UnicodeString*)
|
||||
NLS_TextBoundaryGetText(TextBoundary * that);
|
||||
|
||||
/**
|
||||
* Gets the offset of the first boundary. Moves the current break
|
||||
* state to the new offset. Will return the offset of the text boundary
|
||||
* or NLS_TextBoundryDone if there are no more boundry positions.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(TextOffset)
|
||||
NLS_TextBoundaryFirst(TextBoundary * that);
|
||||
|
||||
/**
|
||||
* Gets the offset of the Last boundary. Moves the current break
|
||||
* state to the new offset. Will return the offset of the text boundary
|
||||
* or NLS_TextBoundryDone if there are no more boundry positions.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(TextOffset)
|
||||
NLS_TextBoundaryLast(TextBoundary * that);
|
||||
|
||||
/**
|
||||
* Gets the offset of the Next boundary. Moves the current break
|
||||
* state to the new offset. Will return the offset of the text boundary
|
||||
* or NLS_TextBoundryDone if there are no more boundry positions.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(TextOffset)
|
||||
NLS_TextBoundaryNext(TextBoundary * that);
|
||||
|
||||
/**
|
||||
* Gets the offset of the Previous boundary. Moves the current break
|
||||
* state to the new offset. Will return the offset of the text boundary
|
||||
* or NLS_TextBoundryDone if there are no more boundry positions.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(TextOffset)
|
||||
NLS_TextBoundaryPrevious(TextBoundary * that);
|
||||
|
||||
/**
|
||||
* Gets the offset of the Current boundary. Moves the current break
|
||||
* state to the new offset. Will return the offset of the text boundary
|
||||
* or NLS_TextBoundryDone if there are no more boundry positions.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(TextOffset)
|
||||
NLS_TextBoundaryCurrent(TextBoundary * that);
|
||||
|
||||
/**
|
||||
* Gets the offset of the Next boundary after the TextOffset specified.
|
||||
* Moves the current break state to the new offset. Will return the offset
|
||||
* of the text boundary or NLS_TextBoundryDone if there are no more
|
||||
* boundry positions.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(TextOffset)
|
||||
NLS_TextBoundaryNextAfter(TextBoundary * that,
|
||||
TextOffset offset);
|
||||
|
||||
/******************** TextBoundary Locale API ************************/
|
||||
|
||||
/**
|
||||
* Get the count of the set of Locales are installed
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(size_t)
|
||||
NLS_TextBoundaryCountAvailableLocales();
|
||||
|
||||
/**
|
||||
* Get the set of Locales for which, the array must be
|
||||
* allocated by the caller, and count must specify how many entries exist.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_TextBoundaryGetAvailableLocales(Locale * LocaleArray,
|
||||
size_t inCount,
|
||||
size_t *count);
|
||||
|
||||
/**
|
||||
* Getter for display of the entire locale to user.
|
||||
* If the localized name is not found, uses the ISO codes.
|
||||
* The default locale is used for the presentation language.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_TextBoundaryGetDisplayName(UnicodeString * name);
|
||||
|
||||
/**
|
||||
* Getter for display of the entire locale to user.
|
||||
* If the localized name is not found, uses the ISO codes
|
||||
* @param inLocale specifies the desired user language.
|
||||
*/
|
||||
NLSBRKAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_TextBoundaryGetDisplayNameInLocale(const Locale * locale,
|
||||
const Locale * inLocale, UnicodeString * name);
|
||||
|
||||
/************************ End ******************************/
|
||||
NLS_END_PROTOS
|
||||
#endif /* _NLSTXB_H */
|
||||
|
|
@ -0,0 +1,482 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _NLSUNI_H
|
||||
#define _NLSUNI_H
|
||||
|
||||
|
||||
#include "nlsxp.h"
|
||||
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
#include "unistring.h"
|
||||
#include "unicode.h"
|
||||
#endif
|
||||
|
||||
NLS_BEGIN_PROTOS
|
||||
|
||||
/**************************** Types *********************************/
|
||||
|
||||
/**
|
||||
* LESS is returned if source string is compared to be less than target
|
||||
* string in the compare() method.
|
||||
* EQUAL is returned if source string is compared to be equal to target
|
||||
* string in the compare() method.
|
||||
* GREATER is returned if source string is compared to be greater than
|
||||
* target string in the compare() method.
|
||||
*/
|
||||
typedef int NLS_ComparisonResult;
|
||||
enum _NLS_ComparisonResult {
|
||||
NLS_LESS = -1,
|
||||
NLS_EQUAL = 0,
|
||||
NLS_GREATER = 1
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Public data for enumerated Unicode general category types
|
||||
*/
|
||||
typedef int NLS_UniCharType;
|
||||
enum _NLS_UniCharType {
|
||||
NLS_UNASSIGNED = 0,
|
||||
NLS_UPPERCASE_LETTER = 1,
|
||||
NLS_LOWERCASE_LETTER = 2,
|
||||
NLS_TITLECASE_LETTER = 3,
|
||||
NLS_MODIFIER_LETTER = 4,
|
||||
NLS_OTHER_LETTER = 5,
|
||||
NLS_NON_SPACING_MARK = 6,
|
||||
NLS_ENCLOSING_MARK = 7,
|
||||
NLS_COMBINING_SPACING_MARK = 8,
|
||||
NLS_DECIMAL_DIGIT_NUMBER = 9,
|
||||
NLS_LETTER_NUMBER = 10,
|
||||
NLS_OTHER_NUMBER = 11,
|
||||
NLS_SPACE_SEPARATOR = 12,
|
||||
NLS_LINE_SEPARATOR = 13,
|
||||
NLS_PARAGRAPH_SEPARATOR = 14,
|
||||
NLS_CONTROL = 15,
|
||||
NLS_FORMAT = 16,
|
||||
NLS_PRIVATE_USE = 17,
|
||||
NLS_SURROGATE = 18,
|
||||
NLS_DASH_PUNCTUATION = 19,
|
||||
NLS_START_PUNCTUATION = 20,
|
||||
NLS_END_PUNCTUATION = 21,
|
||||
NLS_CONNECTOR_PUNCTUATION = 22,
|
||||
NLS_OTHER_PUNCTUATION = 23,
|
||||
NLS_MATH_SYMBOL = 24,
|
||||
NLS_CURRENCY_SYMBOL = 25,
|
||||
NLS_MODIFIER_SYMBOL = 26,
|
||||
NLS_OTHER_SYMBOL = 27,
|
||||
NLS_GENERAL_TYPES_COUNT = 28
|
||||
};
|
||||
|
||||
|
||||
/* UnicodeString is the basic type which replaces the char* datatype.
|
||||
- A UnicodeString is an opaque data type, the Unicode String Accessors must be
|
||||
used to access the data.
|
||||
*/
|
||||
#ifndef NLS_CPLUSPLUS
|
||||
typedef struct _UnicodeString UnicodeString;
|
||||
#endif
|
||||
|
||||
|
||||
/********************* UnicodeString Constructor functions *******************************/
|
||||
/* Constructors for UnicodeStrings, an Empty Unicode String */
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewUnicodeString(UnicodeString ** result);
|
||||
|
||||
/* Constructors for UnicodeStrings, a copy of an Unicode String */
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewUnicodeStringFromUnicodeString(UnicodeString ** result,
|
||||
const UnicodeString * source);
|
||||
|
||||
/* Constructors for UnicodeStrings, a copy of an UniChar[] */
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewUnicodeStringFromUniChar(UnicodeString ** result,
|
||||
const UniChar * that, size_t thatLength);
|
||||
|
||||
/* Constructors for UnicodeStrings, a copy of a Char[] */
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewUnicodeStringFromChar(UnicodeString ** result,
|
||||
const char * that, const char * from_charset);
|
||||
|
||||
/********************* UnicodeString Destructor functions *******************************/
|
||||
/* Destructor for an UnicodeStrings */
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteUnicodeString(UnicodeString * that);
|
||||
|
||||
/********************* UnicodeString easy conversion functions *******************************/
|
||||
|
||||
NLSUNIAPI_PUBLIC(size_t)
|
||||
NLS_CharSizeForUnicodeString(const UnicodeString * source, const char * to_charset);
|
||||
|
||||
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_CharFromUnicodeString(const UnicodeString * source,
|
||||
char * buffer, size_t bufferLength,
|
||||
const char * to_charset);
|
||||
|
||||
|
||||
|
||||
/********************* UnicodeString Comparison functions *******************************/
|
||||
|
||||
/** Compares a UnicodeString to something else
|
||||
* All versions of compare() do bitwise comparison; internationally-
|
||||
* sensitive comparison requires the NLS_Collation API's. */
|
||||
|
||||
|
||||
/* Comparison for two UnicodeStrings */
|
||||
NLSUNIAPI_PUBLIC(NLS_ComparisonResult)
|
||||
NLS_UnicodeStringCompare(const UnicodeString * source, const UnicodeString * target);
|
||||
|
||||
/* Comparison offsets for two UnicodeStrings */
|
||||
NLSUNIAPI_PUBLIC(NLS_ComparisonResult)
|
||||
NLS_UnicodeStringCompareOffset(const UnicodeString * source, TextOffset sourceOffset,
|
||||
size_t sourcelength, const UnicodeString * target,
|
||||
TextOffset targetOffset, size_t targetLength);
|
||||
|
||||
/* Comparison offsets for two UnicodeStrings */
|
||||
NLSUNIAPI_PUBLIC(NLS_ComparisonResult)
|
||||
NLS_UnicodeStringCompareRange(const UnicodeString * source, TextOffset sourceStartOffset,
|
||||
TextOffset sourceEndOffset, const UnicodeString * target,
|
||||
TextOffset targetStartOffset, TextOffset targetEndOffset);
|
||||
|
||||
|
||||
/* Comparison to a UniChar[] */
|
||||
NLSUNIAPI_PUBLIC(NLS_ComparisonResult)
|
||||
NLS_UnicodeStringCompareToUniChar(const UnicodeString * source,
|
||||
const UniChar * target, size_t targetLength);
|
||||
|
||||
/* Case Insensitive comparison */
|
||||
|
||||
/* Comparison UnicodeString */
|
||||
NLSUNIAPI_PUBLIC(NLS_ComparisonResult)
|
||||
NLS_UnicodeStringCompareIgnoreCase(const UnicodeString * source, const UnicodeString * target);
|
||||
|
||||
/* Comparison to a UniChar[] */
|
||||
NLSUNIAPI_PUBLIC(NLS_ComparisonResult)
|
||||
NLS_UnicodeStringCompareIgnoreCaseToUniChar(const UnicodeString * source,
|
||||
const UniChar * target, size_t targetLength);
|
||||
|
||||
/********************* UnicodeString Binary Operator functions *******************************/
|
||||
/* Equal for two UnicodeStrings */
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_UnicodeStringEqual(const UnicodeString * source, const UnicodeString * target);
|
||||
|
||||
/* Not Equal for two UnicodeStrings */
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_UnicodeStringNotEqual(const UnicodeString * source, const UnicodeString * target);
|
||||
|
||||
/* Greater Than for two UnicodeStrings */
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_UnicodeStringGreaterThan(const UnicodeString * source, const UnicodeString * target);
|
||||
|
||||
/* Less Than for two UnicodeStrings */
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_UnicodeStringLessThan(const UnicodeString * source, const UnicodeString * target);
|
||||
|
||||
/* Empty UnicodeStrings */
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_UnicodeStringIsEmpty(const UnicodeString * source);
|
||||
|
||||
/********************* UnicodeString Accessor functions *******************************/
|
||||
/** Allows UnicodeString to be used with interfaces that use UniChar*.
|
||||
* Returns a pointer to the UnicodeString's internal storage. This
|
||||
* storage is still owned by the UnicodeString, and the caller is not
|
||||
* allowed to change it. The string returned by this function is
|
||||
* correctly null-terminated. */
|
||||
|
||||
NLSUNIAPI_PUBLIC(const UniChar *)
|
||||
NLS_UnicodeStringAccessUniCharArray(const UnicodeString * source);
|
||||
|
||||
/** Return the UniChar at the given index
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(UniChar)
|
||||
NLS_UnicodeStringIndexUniChar(const UnicodeString * source, TextOffset offset);
|
||||
|
||||
|
||||
/** Extract a substring
|
||||
* Extracts the specified substring of the UnicodeString into the
|
||||
* storage referred to by extractInto. */
|
||||
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringSubstring(const UnicodeString * source,
|
||||
TextOffset thisOffset, size_t thisLength,
|
||||
UnicodeString * result);
|
||||
|
||||
/** Extract a substring
|
||||
* The UniChar[] extractInto must be at least thislength+1
|
||||
*/
|
||||
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringSubstringUniChar(const UnicodeString * source,
|
||||
TextOffset thisOffset, size_t thisLength,
|
||||
UniChar * extractInto);
|
||||
|
||||
|
||||
/** Extract a substring
|
||||
* Same as extract(), but the substring is specified as starting and
|
||||
* ending offsets (the range is [thisStart, thisEnd) ), rather than
|
||||
* as a starting offset and a length. */
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringSubstringBetween(const UnicodeString * source,
|
||||
TextOffset thisStart, TextOffset thisEnd,
|
||||
UnicodeString * result);
|
||||
|
||||
|
||||
/** Concatenate UnicodeStrings
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringConcatenateUnicodeString(UnicodeString * target,
|
||||
const UnicodeString * source);
|
||||
|
||||
/** Concatenate a UniChar[]
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringConcatenateUniChar(UnicodeString * target,
|
||||
const UniChar * source);
|
||||
|
||||
/** Insert a UnicodeString
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringInsertUnicodeString(UnicodeString * target,
|
||||
TextOffset thisOffset,
|
||||
const UnicodeString* source);
|
||||
|
||||
/** Insert a UniChar[]
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringInsertUniChar(UnicodeString * target,
|
||||
TextOffset thisOffset,
|
||||
const UniChar * source);
|
||||
|
||||
/** delete characters,
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringRemove(UnicodeString * target,
|
||||
TextOffset offset, size_t length);
|
||||
|
||||
/** delete characters
|
||||
* Same as remove(), but the range of characters to delete is specified
|
||||
* as a pair of starting and ending offsets [start, end), rather than
|
||||
* a starting offset and a character count. */
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringRemoveBetween(UnicodeString * target,
|
||||
TextOffset start, TextOffset end);
|
||||
|
||||
/** Replace Range, for UnicodeString, UniChar[], and Char[]
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringReplace(UnicodeString * target,
|
||||
TextOffset targetOffset, size_t targetLength,
|
||||
const UnicodeString * source,
|
||||
TextOffset sourceOffset, size_t sourceLength);
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringReplaceUniChar(UnicodeString * target,
|
||||
TextOffset targetOffset, size_t targetLength,
|
||||
const UniChar * source, size_t sourceLength);
|
||||
|
||||
/** replace characters
|
||||
* Same as replace(), but the affected subranges are specified as
|
||||
* pairs of starting and ending offsets ( [start, end) ) rather than
|
||||
* starting offsets and lengths. */
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringReplaceBetween(UnicodeString * target,
|
||||
TextOffset targetStart, TextOffset targetEnd,
|
||||
const UnicodeString * source,
|
||||
TextOffset sourceStart, TextOffset sourceEnd);
|
||||
|
||||
/**
|
||||
* Scanning, and indexing, returns TextOffset within target, or -1
|
||||
* if the substring does not exist.
|
||||
*
|
||||
*/
|
||||
|
||||
NLSUNIAPI_PUBLIC(TextOffset)
|
||||
NLS_UnicodeStringIndexOfString(const UnicodeString * target,
|
||||
TextOffset startOffset,
|
||||
const UnicodeString * subString);
|
||||
|
||||
NLSUNIAPI_PUBLIC(TextOffset)
|
||||
NLS_UnicodeStringLastIndexOfString(const UnicodeString * target,
|
||||
TextOffset startOffset,
|
||||
const UnicodeString * subString);
|
||||
|
||||
NLSUNIAPI_PUBLIC(TextOffset)
|
||||
NLS_UnicodeStringIndexOfUniChar(const UnicodeString * target,
|
||||
TextOffset startOffset,
|
||||
const UniChar * subString,
|
||||
size_t subStringLength);
|
||||
|
||||
NLSUNIAPI_PUBLIC(TextOffset)
|
||||
NLS_UnicodeStringLastIndexOfUniChar(const UnicodeString * target,
|
||||
TextOffset startOffset,
|
||||
const UniChar * subString,
|
||||
size_t subStringLength);
|
||||
|
||||
|
||||
/** Locale InSensitive toUpper & toLower
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringtoUpper(UnicodeString * target);
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UnicodeStringtoLower(UnicodeString * target);
|
||||
|
||||
/** Return the Size of the UnicodeString
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(size_t)
|
||||
NLS_UnicodeStringSize(const UnicodeString * source);
|
||||
|
||||
/************************ UniChar Type Methods ******************************/
|
||||
|
||||
/*
|
||||
* Creates a UniChar* from a char*.
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewUniCharFromChar(UniChar** uniChar, const char *from_charset, const byte *inputBuffer, size_t inputBufferLength);
|
||||
|
||||
/*
|
||||
* Create a new UniChar* from a UniChar*
|
||||
* May return NULL in the case of a memory allocation failure
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_NewUniCharFromUniChar(UniChar** uniChar, const UniChar *inputBuffer, size_t uniCharCount);
|
||||
|
||||
/*
|
||||
* deletes the memory associated with a UniChar*
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_DeleteUniChar(UniChar* uniChar);
|
||||
|
||||
/** normally, UniChar string is not null terminated,
|
||||
** and there's no simple way to get the length from the array.
|
||||
*/
|
||||
/** Return the Length of the UniChar string
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(size_t)
|
||||
NLS_UniCharLength(const UniChar *src);
|
||||
|
||||
/** Locale InSensitive toUpper & toLower
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UniChartoUpper(UniChar * target, size_t length);
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode)
|
||||
NLS_UniChartoLower(UniChar * target, size_t length);
|
||||
|
||||
/* Comparison for two UniChar */
|
||||
NLSUNIAPI_PUBLIC(NLS_ComparisonResult)
|
||||
NLS_UniCharCompare(const UniChar * source, size_t sourceLength, const UniChar * target, size_t targetLength);
|
||||
|
||||
/* Comparison UniChar */
|
||||
NLSUNIAPI_PUBLIC(NLS_ComparisonResult)
|
||||
NLS_UniCharCompareIgnoreCase(const UniChar * source, size_t sourceLength, const UniChar * target, size_t targetLength);
|
||||
|
||||
/* Equal for two UniChar */
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_UniCharEqual(const UniChar * source, size_t sourceLength, const UniChar * target, size_t targetLength);
|
||||
|
||||
/* Not Equal for two UniChar */
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_UniCharNotEqual(const UniChar * source, size_t sourceLength, const UniChar * target, size_t targetLength);
|
||||
|
||||
/* Greater Than for two UniChar */
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_UniCharGreaterThan(const UniChar * source, size_t sourceLength, const UniChar * target, size_t targetLength);
|
||||
|
||||
/* Less Than for two UniChar */
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_UniCharLessThan(const UniChar * source, size_t sourceLength, const UniChar * target, size_t targetLength);
|
||||
|
||||
/**
|
||||
* Scanning, and indexing, returns TextOffset within target, or -1
|
||||
* if the substring does not exist.
|
||||
*
|
||||
*/
|
||||
|
||||
NLSUNIAPI_PUBLIC(TextOffset)
|
||||
NLS_UniCharIndexOfString(const UniChar * target, size_t targetLength,
|
||||
TextOffset startOffset,
|
||||
const UniChar * subString, size_t subStringLength);
|
||||
|
||||
NLSUNIAPI_PUBLIC(TextOffset)
|
||||
NLS_UniCharLastIndexOfString(const UniChar * target, size_t targetLength,
|
||||
TextOffset startOffset,
|
||||
const UniChar * subString, size_t subStringLength);
|
||||
|
||||
/*
|
||||
* UniChar character functions
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_IsLowerCase (UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_IsUpperCase (UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_IsTitleCase (UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_IsDigit (UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_IsDefined (UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_IsSpaceChar (UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_IsLetter (UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(UniChar)
|
||||
NLS_ToLowerCase (UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(UniChar)
|
||||
NLS_ToUpperCase (UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(UniChar)
|
||||
NLS_ToTitleCase (UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(NLS_UniCharType)
|
||||
NLS_GetType(UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(const UniChar*)
|
||||
NLS_UniCharStrchr(const UniChar* target, size_t targetLength, UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(const UniChar*)
|
||||
NLS_UniCharStrrchr(const UniChar* target, size_t targetLength, UniChar ch);
|
||||
|
||||
NLSUNIAPI_PUBLIC(NLS_ComparisonResult)
|
||||
NLS_UniCharFileNameCompare(const UniChar* source, size_t sourceLength, const UniChar* target, size_t targetLength);
|
||||
|
||||
NLSUNIAPI_PUBLIC(UniChar*)
|
||||
NLS_UniCharAppendString(const UniChar* source, size_t sourceLength, const UniChar* target, size_t targetLength);
|
||||
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_UniCharRegularExpressionSearch(const UniChar* source, size_t sourceLength, const char *expression);
|
||||
|
||||
NLSUNIAPI_PUBLIC(nlsBool)
|
||||
NLS_UniCharRegularUniCharExpressionSearch(const UniChar* source, size_t sourceLength, const UniChar* uExpression, size_t uExpressionLength);
|
||||
|
||||
/************************ Formatting ******************************/
|
||||
|
||||
NLSUNIAPI_PUBLIC(size_t)
|
||||
NLS_SPrintF (UnicodeString *result, const UnicodeString *pattern, ...);
|
||||
|
||||
|
||||
/************************ End ******************************/
|
||||
NLS_END_PROTOS
|
||||
#endif /* _NLSUNI_H */
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NLSUTL_H
|
||||
#define _NLSUTL_H
|
||||
|
||||
|
||||
#include "nlsxp.h"
|
||||
#include "nlsenc.h"
|
||||
|
||||
NLS_BEGIN_PROTOS
|
||||
|
||||
|
||||
/******************** Accept Language List ************************/
|
||||
#define NLS_MAX_ACCEPT_LANGUAGE 16
|
||||
#define NLS_MAX_ACCEPT_LENGTH 18
|
||||
typedef char NLS_ACCEPT_LANGUAGE_LIST[NLS_MAX_ACCEPT_LANGUAGE][NLS_MAX_ACCEPT_LENGTH];
|
||||
|
||||
/* NLS_AcceptLangList
|
||||
*
|
||||
* Will parse an Accept-Language string of the form
|
||||
* "en;q=1.0,fr;q=0.9..."
|
||||
* The NLS_ACCEPT_LANGUAGE_LIST array will be loaded with the ordered
|
||||
* language elements based on the priority of the languages specified.
|
||||
* The number of languages will be returned as the result of the
|
||||
* call.
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(size_t)
|
||||
NLS_AcceptLangList(
|
||||
const char * acceptLanguage,
|
||||
NLS_ACCEPT_LANGUAGE_LIST acceptLanguageList
|
||||
);
|
||||
|
||||
/******************** Accept Charset List ************************/
|
||||
#define NLS_MAX_ACCEPT_CHARSET 16
|
||||
#define NLS_MAX_ACCEPT_CHARSET_LENGTH 128
|
||||
typedef char NLS_ACCEPT_CHARSET_LIST[NLS_MAX_ACCEPT_CHARSET][NLS_MAX_ACCEPT_CHARSET_LENGTH];
|
||||
|
||||
/* NLS_AcceptCharsetList
|
||||
*
|
||||
* Will parse an Accept-Charset string of the form
|
||||
* "UTF8;q=0.9,SJIS;q=0.8;*;q=1.0,..."
|
||||
* The NLS_ACCEPT_CHARSET_LIST array will be loaded with the ordered
|
||||
* charset elements based on the priority of the charset specified.
|
||||
* The number of charsets will be returned as the result of the
|
||||
* call. The NLS_ACCEPT_CHARSET_LIST will be loaded with normalized
|
||||
* charset names. "*" is considered as a valid charset name, and will
|
||||
* be sorted as a charset.
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(size_t)
|
||||
NLS_AcceptCharsetList(
|
||||
const char * acceptCharset,
|
||||
NLS_ACCEPT_CHARSET_LIST acceptCharsetList
|
||||
);
|
||||
|
||||
/* NLS_TargetEncodingFromCharsetList
|
||||
*
|
||||
* Returns the best target encoding for Accept-charset list.
|
||||
* The routine takes a NLS_ACCEPT_CHARSET_LIST returned by
|
||||
* NLS_AcceptCharsetList and returns the best target encoding
|
||||
* based on the sourceEncoding specified. The target encoding will
|
||||
* be a normalized encoding name. The result of this routine may
|
||||
* be NULL if no target encoding is found, or if the target encoding
|
||||
* is identical to the source encoding.
|
||||
*/
|
||||
|
||||
NLSUNIAPI_PUBLIC(const char*)
|
||||
NLS_TargetEncodingFromCharsetList(
|
||||
const char* sourceEncoding,
|
||||
NLS_ACCEPT_CHARSET_LIST acceptCharsetList,
|
||||
size_t count
|
||||
);
|
||||
|
||||
/********************* Character Name Entities *******************/
|
||||
|
||||
/* NLS_Latin1NameEntityValue
|
||||
*
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(NLS_ErrorCode) NLS_Latin1NameEntityValue(
|
||||
const char * name,
|
||||
int *value
|
||||
);
|
||||
|
||||
|
||||
/************************ End ******************************/
|
||||
NLS_END_PROTOS
|
||||
#endif /* _NLSUTL_H */
|
||||
|
|
@ -0,0 +1,613 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NLSNLS_H
|
||||
#define _NLSNLS_H
|
||||
|
||||
/***********************************************************************
|
||||
**
|
||||
** Type definitions are provided by NSPR20, using prtypes.h
|
||||
**
|
||||
************************************************************************/
|
||||
#include "prtypes.h"
|
||||
|
||||
/** need to have nil and NULL defined regardless of system **/
|
||||
#ifndef nil
|
||||
#define nil 0
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
/* which system are we on, get the base macro defined */
|
||||
|
||||
|
||||
|
||||
#if defined(macintosh) || defined(__MWERKS__) || defined(applec)
|
||||
#ifndef macintosh
|
||||
#define macintosh 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__unix) || defined(unix) || defined(UNIX) || defined(XP_UNIX)
|
||||
#ifndef unix
|
||||
#define unix 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(macintosh) && !defined(_WINDOWS) && !defined(_CONSOLE) && !defined(unix)
|
||||
/* #error nls library can't determine system type */
|
||||
#endif
|
||||
|
||||
/* flush out all the system macros */
|
||||
|
||||
#ifdef macintosh
|
||||
# ifndef NLS_MAC
|
||||
# define NLS_MAC 1
|
||||
# endif
|
||||
#if defined(powerc) || defined(__powerc)
|
||||
#ifndef NLS_MAC_PPC
|
||||
#define NLS_MAC_PPC 1
|
||||
#endif /* NLS_MAC_PPC */
|
||||
#else /* powerpc */
|
||||
#ifndef NLS_MAC_68K
|
||||
#define NLS_MAC_68K 1
|
||||
#endif /* NLS_MAC_68K */
|
||||
#endif /* else powerpc */
|
||||
# define NLS_IS_MAC 1
|
||||
# define NLS_MAC_ARG(x) x
|
||||
#else
|
||||
# define NLS_IS_MAC 0
|
||||
# define NLS_MAC_ARG(x)
|
||||
#endif
|
||||
|
||||
#if defined(_WINDOWS) || defined(XP_PC) || defined(_CONSOLE)
|
||||
#ifndef NLS_HAVE_DLL
|
||||
# define NLS_HAVE_DLL
|
||||
#endif /* NLS_HAVE_DLL */
|
||||
#ifndef NLS_PC
|
||||
# define NLS_PC
|
||||
#endif /* ifndef NLS_PC */
|
||||
#ifndef NLS_WIN
|
||||
# define NLS_WIN
|
||||
#endif /* ifndef NLS_WIN */
|
||||
# define NLS_IS_WIN 1
|
||||
# define NLS_WIN_ARG(x) x
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
#ifndef NLS_WIN32
|
||||
# define NLS_WIN32
|
||||
#endif /* NLS_WIN32 */
|
||||
#else /* defined(_WIN32) || defined(WIN32) */
|
||||
#ifndef NLS_WIN16
|
||||
# define NLS_WIN16
|
||||
#endif /* NLS_WIN16 */
|
||||
#endif /* defined(_WIN32) || defined(WIN32) */
|
||||
#else /* defined(_WINDOWS) || defined(XP_PC) */
|
||||
# define NLS_IS_WIN 0
|
||||
# define NLS_WIN_ARG(x)
|
||||
#endif /* defined(_WINDOWS) || defined(XP_PC) */
|
||||
|
||||
#ifdef unix
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#if defined(HPUX)
|
||||
#ifndef NLS_HAVE_DLL
|
||||
# define NLS_HAVE_DLL
|
||||
#endif /* NLS_HAVE_DLL */
|
||||
#ifndef NLS_USE_HPSHL
|
||||
# define NLS_USE_HPSHL
|
||||
#endif /* NLS_USE_HPSHL */
|
||||
#endif /* defined(HPUX) */
|
||||
|
||||
/* Figure out if we are on AIX, and Set NLS variable */
|
||||
#if defined(_AIX42) || defined (AIX4_2)
|
||||
#define NLS_AIX42 1
|
||||
#undef NLS_AIX41
|
||||
#else
|
||||
#if defined (_AIX41) || defined (AIX4_1)
|
||||
#define NLS_AIX41 1
|
||||
#undef NLS_AIX42
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* UNIX Platforms with DLL capibalities */
|
||||
|
||||
#if defined(IRIX) || defined(LINUX) || defined(SOLARIS) || defined(SUNOS4) || defined(SNI) || defined(SONY) || defined(NECSVR4) || defined(SCO) || defined(UNIXWARE) || defined (AIX) || defined (OSF1) || defined(NLS_AIX41) || defined (NLS_AIX42)
|
||||
#ifndef NLS_HAVE_DLL
|
||||
# define NLS_HAVE_DLL
|
||||
#endif /* NLS_HAVE_DLL */
|
||||
#ifndef NLS_USE_DLFCN
|
||||
# define NLS_USE_DLFCN
|
||||
#endif /* NLS_USE_DLFCN */
|
||||
#endif /* defined(HPUX) */
|
||||
|
||||
/* UNIX Platforms without DLL capabilities */
|
||||
|
||||
#if defined(BSDI) || defined(NCR)
|
||||
#undef NLS_HAVE_DLL
|
||||
#undef NLS_USE_DLFCN
|
||||
#endif
|
||||
|
||||
# ifndef NLS_UNIX
|
||||
# define NLS_UNIX
|
||||
# endif
|
||||
# define NLS_IS_UNIX 1
|
||||
# define NLS_UNIX_ARG(x) x
|
||||
#else
|
||||
# define NLS_IS_UNIX 0
|
||||
# define NLS_UNIX_ARG(x)
|
||||
#endif
|
||||
|
||||
/* what language do we have? */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
# define NLS_CPLUSPLUS
|
||||
# define NLS_IS_CPLUSPLUS 1
|
||||
#else
|
||||
# define NLS_IS_CPLUSPLUS 0
|
||||
#endif
|
||||
|
||||
#if defined (NLS_MAC)
|
||||
#include <stdio.h>
|
||||
#include <ConditionalMacros.h>
|
||||
#include <CodeFragments.h>
|
||||
#include <TextUtils.h>
|
||||
#include <Types.h>
|
||||
#include <Strings.h>
|
||||
#include <Errors.h>
|
||||
#include <Files.h>
|
||||
#include <StandardFile.h>
|
||||
#include <Resources.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
language macros
|
||||
|
||||
If C++ code includes a prototype for a function *compiled* in C, it needs to be
|
||||
wrapped in extern "C" for the linking to work properly. On the Mac, all code is
|
||||
being compiled in C++ so this isn't necessary, and Unix compiles it all in C. So
|
||||
only Windows actually will make use of the defined macros.
|
||||
*/
|
||||
|
||||
#if defined(NLS_CPLUSPLUS)
|
||||
# define NLS_BEGIN_PROTOS extern "C" {
|
||||
# define NLS_END_PROTOS }
|
||||
#else
|
||||
# define NLS_BEGIN_PROTOS
|
||||
# define NLS_END_PROTOS
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
#if defined(_DEBUG) || defined(DEBUG)
|
||||
#if !defined (NLS_WIN16)
|
||||
#define NLS_DEBUG 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined (NLS_DEBUG_INTERNAL)
|
||||
#if defined(NLS_WIN32)
|
||||
#include <assert.h>
|
||||
#include <crtdbg.h>
|
||||
#define NLS_ASSERT(a) if (!(a)) {_ASSERT(a);}
|
||||
#define NLS_ASSERTION(a,b) if (!(a)) {_ASSERT(a);goto b;}
|
||||
#else
|
||||
#if defined (NLS_WIN16)
|
||||
#define NLS_ASSERT(a) ((void)0)
|
||||
#define NLS_ASSERTION(a,b) if (!(a)) { goto b; }
|
||||
#else
|
||||
#if defined (NLS_UNIX)
|
||||
#define NLS_ASSERT(a) ((a) ? ((void)0) : (void)fprintf(stderr, "assert: line %d, file %s%c\n", __LINE__, __FILE__, 7))
|
||||
#define NLS_ASSERTION(a,b) if (!(a)) { (void)fprintf(stderr, "assert: line %d, file %s%c\n", __LINE__, __FILE__, 7) ; goto b; }
|
||||
#else
|
||||
#if defined (NLS_MAC)
|
||||
#define NLS_ASSERT(a) ((void)0)
|
||||
#define NLS_ASSERTION(a,b) if (!(a)) {goto b;}
|
||||
#else
|
||||
#define NLS_ASSERT(a) ((void)0)
|
||||
#define NLS_ASSERTION(a,b) if (!(a)) {goto b;}
|
||||
#endif /* defined (NLS_MAC) */
|
||||
#endif /* defined (NLS_UNIX) */
|
||||
#endif /* defined (NLS_WIN16) */
|
||||
#endif /* defined (NLS_WIN32) */
|
||||
#else /* defined (NLS_DEBUG) */
|
||||
#define NLS_ASSERT(a) ((void)0)
|
||||
#define NLS_ASSERTION(a,b) if (!(a)) {goto b;}
|
||||
#endif /* defined (NLS_DEBUG_INTERNAL) */
|
||||
|
||||
typedef char nlsBool;
|
||||
enum _nlsBool {
|
||||
nlsTrue = 1,
|
||||
nlsFalse = 0
|
||||
};
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
|
||||
/*
|
||||
Define an XPlatform Type for an C function
|
||||
-- on WIN16 using void (*fp)void casts away runtime info....
|
||||
*/
|
||||
|
||||
/*
|
||||
* Define standard types we need if we are being built standalone
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/* standard system headers */
|
||||
|
||||
#if !defined(RC_INVOKED)
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#ifdef __sgi
|
||||
# include <float.h>
|
||||
# include <sys/bsd_types.h>
|
||||
#endif
|
||||
#ifdef NLS_UNIX
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#if defined(NLS_WIN) && defined(NLS_CPLUSPLUS) && defined(_MSC_VER) && _MSC_VER >= 1020
|
||||
/* math.h under MSVC 4.2 needs C++ linkage when C++. */
|
||||
extern "C++" {
|
||||
#include <math.h>
|
||||
}
|
||||
#elif (defined(__hpux) || defined(SCO)) && defined(__cplusplus)
|
||||
extern "C++" {
|
||||
#include <math.h>
|
||||
}
|
||||
#else
|
||||
#include <math.h>
|
||||
#endif
|
||||
#include <setjmp.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if defined(AIX)
|
||||
#include <strings.h> /* strcasecmp, etc. */
|
||||
#endif
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#if defined(NLS_PC)
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#define NLSAPI_EXPORT(__x) _declspec(dllexport) __x
|
||||
#define NLSAPI_IMPORT(__x) _declspec(dllimport) __x
|
||||
#define NLSAPI_CLASS_EXPORT _declspec(dllexport)
|
||||
#define NLSAPI_CLASS_IMPORT _declspec(dllimport)
|
||||
|
||||
#else /* !_WIN32 */
|
||||
|
||||
#if defined(_WINDLL)
|
||||
#define NLSAPI_EXPORT(__x) __x _cdecl _loadds _export
|
||||
#define NLSAPI_IMPORT(__x) __x
|
||||
#define NLSAPI_CLASS_EXPORT _export
|
||||
#define NLSAPI_CLASS_IMPORT
|
||||
|
||||
#else /* !_WINDLL */
|
||||
|
||||
#define NLSAPI_EXPORT(__x) __x _cdecl _export
|
||||
#define NLSAPI_IMPORT(__x) __x
|
||||
#define NLSAPI_CLASS_EXPORT _export
|
||||
#define NLSAPI_CLASS_IMPORT
|
||||
#endif /* ! WINDLL */
|
||||
|
||||
#endif /* !_WIN32 */
|
||||
|
||||
#elif defined(NLS_MAC)
|
||||
/* Mac */
|
||||
#define NLSAPI_EXPORT(__x) __declspec(export) __x
|
||||
#define NLSAPI_IMPORT(__x) __x
|
||||
#define NLSAPI_CLASS_EXPORT
|
||||
#define NLSAPI_CLASS_IMPORT
|
||||
|
||||
#else /* Unix */
|
||||
|
||||
#define NLSAPI_EXPORT(__x) __x
|
||||
#define NLSAPI_IMPORT(__x) __x
|
||||
#define NLSAPI_CLASS_EXPORT
|
||||
#define NLSAPI_CLASS_IMPORT
|
||||
|
||||
#endif /* Unix */
|
||||
|
||||
#if defined(NLS_LIBCNV_IMP)
|
||||
#define NLSCNVAPI_PUBLIC(__x) NLSAPI_EXPORT(__x)
|
||||
#define NLSCNVAPI_PUBLIC_CLASS NLSAPI_CLASS_EXPORT
|
||||
#else
|
||||
#define NLSCNVAPI_PUBLIC(__x) NLSAPI_IMPORT(__x)
|
||||
#define NLSCNVAPI_PUBLIC_CLASS NLSAPI_CLASS_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(NLS_LIBUNI_IMP)
|
||||
#define T_UTILITY_IMPLEMENTATION 1
|
||||
#define NLSUNIAPI_PUBLIC(__x) NLSAPI_EXPORT(__x)
|
||||
#define NLSUNIAPI_PUBLIC_CLASS NLSAPI_CLASS_EXPORT
|
||||
#else
|
||||
#define NLSUNIAPI_PUBLIC(__x) NLSAPI_IMPORT(__x)
|
||||
#define NLSUNIAPI_PUBLIC_CLASS NLSAPI_CLASS_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(NLS_LIBCOL_IMP)
|
||||
#define T_COLLATE_IMPLEMENTATION 1
|
||||
#define NLSCOLAPI_PUBLIC(__x) NLSAPI_EXPORT(__x)
|
||||
#define NLSCOLAPI_PUBLIC_CLASS NLSAPI_CLASS_EXPORT
|
||||
#else
|
||||
#define NLSCOLAPI_PUBLIC(__x) NLSAPI_IMPORT(__x)
|
||||
#define NLSCOLAPI_PUBLIC_CLASS NLSAPI_CLASS_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(NLS_LIBBRK_IMP)
|
||||
#define T_FINDWORD_IMPLEMENTATION 1
|
||||
#define NLSBRKAPI_PUBLIC(__x) NLSAPI_EXPORT(__x)
|
||||
#define NLSBRKAPI_PUBLIC_CLASS NLSAPI_CLASS_EXPORT
|
||||
#else
|
||||
#define NLSBRKAPI_PUBLIC(__x) NLSAPI_IMPORT(__x)
|
||||
#define NLSBRKAPI_PUBLIC_CLASS NLSAPI_CLASS_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(NLS_LIBFMT_IMP)
|
||||
#define T_FORMAT_IMPLEMENTATION 1
|
||||
#define NLSFMTAPI_PUBLIC(__x) NLSAPI_EXPORT(__x)
|
||||
#define NLSFMTAPI_PUBLIC_CLASS NLSAPI_CLASS_EXPORT
|
||||
#else
|
||||
#define NLSFMTAPI_PUBLIC(__x) NLSAPI_IMPORT(__x)
|
||||
#define NLSFMTAPI_PUBLIC_CLASS NLSAPI_CLASS_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(NLS_LIBRES_IMP)
|
||||
#define NLSRESAPI_PUBLIC(__x) NLSAPI_EXPORT(__x)
|
||||
#define NLSRESAPI_PUBLIC_CLASS NLSAPI_CLASS_EXPORT
|
||||
#else
|
||||
#define NLSRESAPI_PUBLIC(__x) NLSAPI_IMPORT(__x)
|
||||
#define NLSRESAPI_PUBLIC_CLASS NLSAPI_CLASS_IMPORT
|
||||
#endif
|
||||
|
||||
#if defined(NLS_LIBPRS_IMP)
|
||||
#define NLSPRSAPI_PUBLIC(__x) NLSAPI_EXPORT(__x)
|
||||
#define NLSPRSAPI_PUBLIC_CLASS NLSAPI_CLASS_EXPORT
|
||||
#else
|
||||
#define NLSPRSAPI_PUBLIC(__x) NLSAPI_IMPORT(__x)
|
||||
#define NLSPRSAPI_PUBLIC_CLASS NLSAPI_CLASS_IMPORT
|
||||
#endif
|
||||
|
||||
/*
|
||||
* huge memory model for Win16, yes we do have some huge arrays
|
||||
*/
|
||||
|
||||
#ifdef NLS_WIN16
|
||||
#define NLS_HUGE __huge
|
||||
#define HUGEP __huge
|
||||
#else
|
||||
#define NLS_HUGE
|
||||
#define HUGEP
|
||||
#endif
|
||||
|
||||
/**
|
||||
** farproc for non-windows platforms
|
||||
**/
|
||||
#ifdef NSPR20
|
||||
#ifndef NLS_WIN
|
||||
|
||||
#ifndef XP_UNIX
|
||||
#define FARPROC void*
|
||||
#else
|
||||
#include "md/_unixos.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#else
|
||||
#ifdef NLS_UNIX
|
||||
#include "prunixos.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NLS_WIN
|
||||
#define MODULE_PATH_LENGTH 255 /* maximum path+filename length for getting DLL names */
|
||||
#endif
|
||||
|
||||
#ifdef NLS_WIN16
|
||||
NLS_BEGIN_PROTOS
|
||||
|
||||
|
||||
/*
|
||||
** The following RTL routines are unavailable for WIN16 DLLs
|
||||
*/
|
||||
#ifdef _WINDLL
|
||||
|
||||
#include "windows.h"
|
||||
|
||||
/* XXX: Need to include all of the winsock calls as well... */
|
||||
NLSCNVAPI_PUBLIC(int) sscanf(const char *, const char *, ...);
|
||||
NLSCNVAPI_PUBLIC(int) fscanf(FILE *stream, const char *, ...);
|
||||
#endif /* _WINDLL */
|
||||
|
||||
NLS_END_PROTOS
|
||||
|
||||
#endif /* NLS_WIN16 */
|
||||
|
||||
|
||||
|
||||
/** Thread info for NLS libary to use
|
||||
* lock: lock variable
|
||||
* fn_lock: thread lock API
|
||||
* fn_unlock: thread unlock API
|
||||
*/
|
||||
#include "muteximp.h"
|
||||
|
||||
typedef MutexImplementation NLS_ThreadInfo;
|
||||
|
||||
/* X-platform stuff for directories */
|
||||
#ifdef NLS_MAC
|
||||
#define NLS_DIRECTORY_SEPARATOR '/'
|
||||
#define NLS_DIRECTORY_SEPARATOR_STR "/"
|
||||
#endif
|
||||
|
||||
#ifdef NLS_PC
|
||||
#define NLS_DIRECTORY_SEPARATOR '\\'
|
||||
#define NLS_DIRECTORY_SEPARATOR_STR "\\"
|
||||
#endif
|
||||
|
||||
#ifdef NLS_UNIX
|
||||
#define NLS_DIRECTORY_SEPARATOR '/'
|
||||
#define NLS_DIRECTORY_SEPARATOR_STR "/"
|
||||
#endif
|
||||
|
||||
/********************* case insensitive comparison *******************************/
|
||||
#if defined(NLS_MAC) || defined(NLS_WIN16)
|
||||
NLS_BEGIN_PROTOS
|
||||
int __strcmpi(const char* s1, const char* s2);
|
||||
NLS_END_PROTOS
|
||||
#define strcasecmp(s1,s2) (__strcmpi(s1,s2))
|
||||
#elif defined (NLS_WIN32)
|
||||
#define strcasecmp(s1,s2) (_stricmp(s1,s2))
|
||||
#endif
|
||||
|
||||
/********************* Unicode Type Names *******************************/
|
||||
|
||||
#if !defined (NLS_MAC) && !defined(AIXV4)/* Defined in Types.h on MAC */
|
||||
typedef wchar_t UniChar;
|
||||
#endif
|
||||
|
||||
/** UCS4 Unicode Char */
|
||||
typedef unsigned long UniCharUCS4;
|
||||
|
||||
|
||||
/********************* Libnls Version Numbers ******************************/
|
||||
|
||||
#define kLibnlsVersion20 "20"
|
||||
#define kLibnlsVersion30 "30"
|
||||
#define kLibnlsVersionCurrent kLibnlsVersion30
|
||||
|
||||
#define kLibnlsCollationVersion300 "3.00"
|
||||
#define kLibnlsCollationVersionCurrent kLibnlsCollationVersion300
|
||||
|
||||
/********************* UnicodeConverter Names *******************************/
|
||||
|
||||
|
||||
#define NLS_MAX_ENCODING_NAME_SIZE 64
|
||||
|
||||
/* Constant name, prefered MIME name IANA standard encoding name */
|
||||
/* --------------------------------- --------------------------- */
|
||||
#define NLS_ENCODING_US_ASCII "ANSI_X3.4-1968"
|
||||
#define NLS_ENCODING_ISO_8859_1 "ISO_8859-1:1987"
|
||||
#define NLS_ENCODING_ISO_8859_2 "ISO_8859-2:1987"
|
||||
#define NLS_ENCODING_ISO_8859_3 "ISO_8859-3:1988"
|
||||
#define NLS_ENCODING_ISO_8859_4 "ISO_8859-4:1988"
|
||||
#define NLS_ENCODING_ISO_8859_5 "ISO_8859-5:1988"
|
||||
#define NLS_ENCODING_ISO_8859_6 "ISO_8859-6:1987"
|
||||
#define NLS_ENCODING_ISO_8859_7 "ISO_8859-7:1987"
|
||||
#define NLS_ENCODING_ISO_8859_8 "ISO_8859-8:1988"
|
||||
#define NLS_ENCODING_ISO_8859_9 "ISO_8859-9:1989"
|
||||
#define NLS_ENCODING_ISO_2022_JP "ISO-2022-JP"
|
||||
#define NLS_ENCODING_SHIFT_JIS "Shift_JIS"
|
||||
#define NLS_ENCODING_EUC_JP "Extended_UNIX_Code_Packed_Format_for_Japanese"
|
||||
#define NLS_ENCODING_ISO_2022_JP "ISO-2022-JP"
|
||||
#define NLS_ENCODING_ISO_2022_JP_2 "ISO-2022-JP-2"
|
||||
#define NLS_ENCODING_JIS_X0208_1983 "JIS_C6226-1983"
|
||||
#define NLS_ENCODING_JIS_X0201 "JIS_X0201"
|
||||
#define NLS_ENCODING_GB2312 "GB2312"
|
||||
#define NLS_ENCODING_EUC_KR "EUC-KR"
|
||||
#define NLS_ENCODING_ISO_2022_KR "ISO-2022-KR"
|
||||
#define NLS_ENCODING_KOI8_R "KOI8-R"
|
||||
#define NLS_ENCODING_BIG5 "Big5"
|
||||
#define NLS_ENCODING_CNS11643_1 "cns11643_1"
|
||||
#define NLS_ENCODING_KSC5601 "KS_C_5601-1987"
|
||||
#define NLS_ENCODING_WINDOWS_1250 "windows-1250"
|
||||
#define NLS_ENCODING_WINDOWS_1251 "windows-1251"
|
||||
#define NLS_ENCODING_UTF_8 "UTF-8"
|
||||
#define NLS_ENCODING_UTF_7 "UNICODE-1-1-UTF-7"
|
||||
#define NLS_ENCODING_MODIFIED_UTF_7 "IMAP-MODIFIED-UTF-7"
|
||||
#define NLS_ENCODING_ISO_10646_UCS_2 "ISO-10646-UCS-2"
|
||||
#define NLS_ENCODING_ISO_10646_UCS_4 "ISO-10646-UCS-4"
|
||||
#define NLS_ENCODING_ESCAPED_UNICODE "ESCAPED_UNICODE"
|
||||
#define NLS_ENCODING_MAC_ROMAN "x-mac-roman"
|
||||
#define NLS_ENCODING_DINGBATS "x-mac-dingbats"
|
||||
#define NLS_ENCODING_SYMBOL "x-mac-symbol"
|
||||
|
||||
|
||||
/* Error codes */
|
||||
|
||||
typedef long NLS_ErrorCode;
|
||||
enum _NLS_ErrorCode {
|
||||
NLS_SUCCESS = 1,
|
||||
NLS_RESULT_TRUNCATED = 2,
|
||||
NLS_USING_DEFAULT_LOCALE = 3,
|
||||
NLS_USING_FALLBACK_LOCALE = 4,
|
||||
NLS_NEW_UNICODESTRING_FAILED = -1001,
|
||||
NLS_MEMORY_ALLOCATION_FAILED = -1002,
|
||||
NLS_NEW_COLLATION_FAILED = -1004,
|
||||
NLS_NEW_SORTKEY_FAILED = -1005,
|
||||
NLS_NEW_LOCALE_FAILED = -1006,
|
||||
NLS_NO_FROM_ENCODING = -1007,
|
||||
NLS_NO_TO_ENCODING = -1008,
|
||||
NLS_PARAM_ERROR = -1009,
|
||||
NLS_MISSING_RESOURCE_ERROR = -1010,
|
||||
NLS_INVALID_FORMAT_ERROR = -1011,
|
||||
NLS_FILE_ACCESS_ERROR = -1012,
|
||||
NLS_BUFFER_TO_SMALL_ERROR = -1013,
|
||||
NLS_NEW_CONVERTER_FAILED = -1014,
|
||||
NLS_NEW_CONVERTER_LIST_FAILED = -1015,
|
||||
NLS_AUTO_DETECTION_ERROR = -1016,
|
||||
NLS_NEW_TEXT_BOUNDARY_FAILED = -1017,
|
||||
NLS_NEW_TIMEZONE_FAILED = -1018,
|
||||
NLS_MESSAGE_PARSE_ERROR = -1019,
|
||||
NLS_INTERNAL_PROGRAM_ERROR = -1020,
|
||||
NLS_FUNCTION_FAILED = -1100,
|
||||
|
||||
NLS_RESOURCE_OPEN_ERROR = -1201,
|
||||
NLS_RESOURCE_NOT_FOUND = -1202,
|
||||
NLS_RESOURCE_IN_CACHE = -1203,
|
||||
NLS_JAR_OPEN_FAILURE = -1204,
|
||||
NLS_BAD_RESOURCE_PATH = -1205,
|
||||
|
||||
NLS_LIB_NOT_FOUND = -1300,
|
||||
NLS_ENCODING_NOT_FOUND = -1301,
|
||||
NLS_BAD_CONVERSION_SOURCE = -1302,
|
||||
NLS_CONVERSION_BUFFER_OVERFLOW = -1303,
|
||||
NLS_CONVERSION_SOURCE_EXHAUSTED = -1304,
|
||||
NLS_ENCODING_REGISTRY_NOT_INITIALIZED = -1305,
|
||||
NLS_LIBRARY_SYMBOL_NOT_FOUND = -1306,
|
||||
NLS_ENCODING_CONVERTER_NOT_INITIALIZED = -1307
|
||||
};
|
||||
|
||||
|
||||
typedef char *NLS_StaticConverterRegistry;
|
||||
|
||||
|
||||
#endif /* _NLSNLS_H */
|
||||
|
||||
|
|
@ -0,0 +1,514 @@
|
|||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1996, 1997 *
|
||||
* (C) Copyright International Business Machines Corporation, 1996, 1997 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
*
|
||||
* FILE NAME : PTYPES.H
|
||||
*
|
||||
* Date Name Description
|
||||
* 12/11/96 helena Creation.
|
||||
* 02/27/97 aliu Added typedefs for ClassID, int8, int16, int32, uint8, uint16,
|
||||
* and uint32.
|
||||
* 04/01/97 aliu Added XP_CPLUSPLUS and modified to work under C as well as C++.
|
||||
* Modified to use memcpy() for arrayCopy() fns.
|
||||
* 04/14/97 aliu Added TPlatformUtilities.
|
||||
* 05/07/97 aliu Added import/export specifiers (replacing the old broken
|
||||
* EXT_CLASS). Added version number for our code. Cleaned up
|
||||
* header.
|
||||
* 6/20/97 helena Java class name change.
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _PTYPES
|
||||
#define _PTYPES
|
||||
|
||||
#include "nlsxp.h"
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*=====================================================================================*/
|
||||
/* Analytics version number */
|
||||
/*=====================================================================================*/
|
||||
|
||||
/**
|
||||
* Analytic package code version number. This version number must be incremented if and
|
||||
* only if the code has changed in a binary incompatible way. For example, if the
|
||||
* algorithm for generating sort keys has changed, this code version must be incremented.
|
||||
*
|
||||
* This is for internal use only. Clients should use ResourceBundle::getVersionNumber().
|
||||
* ResourceBundle::getVersionNumber() returns a full version number for a resource,
|
||||
* which consists of this code version number concatenated with the ResourceBundle data
|
||||
* file version number.
|
||||
*/
|
||||
#define T_ANALYTIC_PACKAGE_VERSION "1"
|
||||
|
||||
/*=====================================================================================*/
|
||||
/* Flags related to testing code coverage */
|
||||
/*=====================================================================================*/
|
||||
|
||||
#define TESTING_CODE_COVERAGE 1 /* defined when executing tests */
|
||||
/* with code coverage reporting */
|
||||
|
||||
/* #define EXTENDED_FUNCTIONALITY */ /* in general this is undefined */
|
||||
|
||||
/*=====================================================================================*/
|
||||
/* Flags specifying host character set */
|
||||
/*=====================================================================================*/
|
||||
|
||||
#define USES_ISO_8859_1 1
|
||||
#define USES_EBCDIC 0
|
||||
|
||||
/*=====================================================================================*/
|
||||
/* Platform/Language determination */
|
||||
/*=====================================================================================*/
|
||||
|
||||
#if defined(__OS2__) || defined (_AIX) || defined(__AS400__)
|
||||
#define USE_POSIX
|
||||
#endif
|
||||
|
||||
|
||||
/*=====================================================================================*/
|
||||
/* Boolean data type */
|
||||
/*=====================================================================================*/
|
||||
|
||||
/* uncomment these lines on compilers that don't directly support "bool" */
|
||||
/* it may be necessary to change this for different platforms */
|
||||
/*
|
||||
typedef char bool;
|
||||
enum {
|
||||
true = 1,
|
||||
false = 0
|
||||
};
|
||||
*/
|
||||
/*Change the bool type to t_bool and true to TRUE and false to FALSE*/
|
||||
/*till all the files are corrected and tested,we will retain both
|
||||
definitions*/
|
||||
#ifdef TRUE
|
||||
#undef TRUE
|
||||
#endif
|
||||
|
||||
#ifdef FALSE
|
||||
#undef FALSE
|
||||
#endif
|
||||
|
||||
typedef char t_bool;
|
||||
enum {
|
||||
TRUE = 1,
|
||||
FALSE = 0
|
||||
};
|
||||
|
||||
/*=====================================================================================*/
|
||||
/* Other generic data types */
|
||||
/*=====================================================================================*/
|
||||
|
||||
/** Unicode character */
|
||||
/*#if sizeof(wchar_t) < 2 */
|
||||
/*#ifndef _AIX / * AIX defines UniChar in /usr/include/sys/types.h */
|
||||
/* typedef unsigned short UniChar; */
|
||||
/*#endif */
|
||||
/*#else */
|
||||
/*typedef wchar_t UniChar; */
|
||||
/*#endif */
|
||||
|
||||
#ifdef NSPR20
|
||||
|
||||
/** Unicode string offset */
|
||||
/*#if sizeof(int) >= 32 */
|
||||
/*typedef int TextOffset; */
|
||||
/*#else */
|
||||
typedef PRInt32 TextOffset;
|
||||
/*#endif */
|
||||
|
||||
/* Before compiling on a new platform, add a section for that platform, */
|
||||
/* defining the sized integral data types. */
|
||||
typedef PRInt8 t_int8;
|
||||
typedef PRUint8 t_uint8;
|
||||
typedef PRInt16 t_int16;
|
||||
typedef PRUint16 t_uint16;
|
||||
typedef PRInt32 t_int32;
|
||||
typedef PRUint32 t_uint32;
|
||||
#define T_INT32_MAX (LONG_MAX)
|
||||
|
||||
#else
|
||||
/** Unicode string offset */
|
||||
/*#if sizeof(int) >= 32 */
|
||||
/*typedef int TextOffset; */
|
||||
/*#else */
|
||||
typedef int32 TextOffset;
|
||||
/*#endif */
|
||||
|
||||
/* Before compiling on a new platform, add a section for that platform, */
|
||||
/* defining the sized integral data types. */
|
||||
typedef int8 t_int8;
|
||||
typedef uint8 t_uint8;
|
||||
typedef int16 t_int16;
|
||||
typedef uint16 t_uint16;
|
||||
typedef int32 t_int32;
|
||||
typedef uint32 t_uint32;
|
||||
#define T_INT32_MAX (LONG_MAX)
|
||||
#define PR_INT32(x) x ## L
|
||||
#endif
|
||||
|
||||
/*=====================================================================================*/
|
||||
/* Calendar/TimeZone data types */
|
||||
/*=====================================================================================*/
|
||||
|
||||
/* Date should be a 64-bit long integer. For systems/compilers */
|
||||
/* that do not support 64-bit long integer, use IEEE double. */
|
||||
/*#if sizeof(long) >= 64 */
|
||||
/*typedef long Date; */
|
||||
/*#else */
|
||||
typedef double Date;
|
||||
/*#endif */
|
||||
|
||||
/* Common time manipulation constants */
|
||||
#define kMillisPerSecond (PR_INT32(1000))
|
||||
#define kMillisPerMinute (PR_INT32(60) * kMillisPerSecond)
|
||||
#define kMillisPerHour (PR_INT32(60) * kMillisPerMinute)
|
||||
#define kMillisPerDay (PR_INT32(24) * kMillisPerHour)
|
||||
|
||||
|
||||
/*=====================================================================================*/
|
||||
/* ClassID-based RTTI */
|
||||
/*=====================================================================================*/
|
||||
|
||||
/**
|
||||
* ClassID is used to identify classes without using RTTI, since RTTI
|
||||
* is not yet supported by all C++ compilers. Each class hierarchy which needs
|
||||
* to implement polymorphic clone() or operator==() defines two methods,
|
||||
* described in detail below. ClassID values can be compared using operator==().
|
||||
* Nothing else should be done with them.
|
||||
*
|
||||
* getDynamicClassID() is declared in the base class of the hierarchy as
|
||||
* a pure virtual. Each concrete subclass implements it in the same way:
|
||||
*
|
||||
* class Base {
|
||||
* public:
|
||||
* virtual ClassID getDynamicClassID() const = 0;
|
||||
* }
|
||||
*
|
||||
* class Derived {
|
||||
* public:
|
||||
* virtual ClassID getDynamicClassID() const
|
||||
* {
|
||||
* return Derived::getStaticClassID();
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Each concrete class implements getStaticClassID() as well, which allows
|
||||
* clients to test for a specific type.
|
||||
*
|
||||
* class Derived {
|
||||
* public:
|
||||
* static ClassID getStaticClassID();
|
||||
* private:
|
||||
* static char fgClassID;
|
||||
* }
|
||||
*
|
||||
* // In Derived.cpp:
|
||||
* ClassID Derived::getStaticClassID() { return (ClassID)&Derived::fgClassID; }
|
||||
* char Derived::fgClassID = 0; // Value is irrelevant
|
||||
*/
|
||||
|
||||
typedef void* ClassID;
|
||||
|
||||
/*=====================================================================================*/
|
||||
/* DLL import-export API control */
|
||||
/*=====================================================================================*/
|
||||
|
||||
/**
|
||||
* Control of DLL import/export. We break the Analytic package into four DLLs;
|
||||
* the Utility, Format, Findword, and Collate DLLs. Each DLL defines the appropriate
|
||||
* compile-time symbol (e.g., T_UTILITY_IMPLEMENTATION) when building. Declarations
|
||||
* of exported API us the appropriate declarator (e.g., T_UTILITY_API).
|
||||
*
|
||||
* If new DLLs are added, this section must be expanded.
|
||||
*/
|
||||
|
||||
#define T_EXPORT NLSAPI_CLASS_EXPORT
|
||||
#define T_IMPORT NLSAPI_CLASS_IMPORT
|
||||
|
||||
#ifdef T_UTILITY_IMPLEMENTATION
|
||||
#define T_UTILITY_API T_EXPORT
|
||||
#define T_COLLATE_API T_IMPORT
|
||||
#define T_FORMAT_API T_IMPORT
|
||||
#define T_FINDWORD_API T_IMPORT
|
||||
#elif defined(T_FINDWORD_IMPLEMENTATION)
|
||||
#define T_UTILITY_API T_IMPORT
|
||||
#define T_COLLATE_API T_IMPORT
|
||||
#define T_FORMAT_API T_IMPORT
|
||||
#define T_FINDWORD_API T_EXPORT
|
||||
#elif defined(T_FORMAT_IMPLEMENTATION)
|
||||
#define T_UTILITY_API T_IMPORT
|
||||
#define T_COLLATE_API T_IMPORT
|
||||
#define T_FORMAT_API T_EXPORT
|
||||
#define T_FINDWORD_API T_IMPORT
|
||||
#elif defined(T_COLLATE_IMPLEMENTATION)
|
||||
#define T_UTILITY_API T_IMPORT
|
||||
#define T_COLLATE_API T_EXPORT
|
||||
#define T_FORMAT_API T_IMPORT
|
||||
#define T_FINDWORD_API T_IMPORT
|
||||
#else
|
||||
#define T_UTILITY_API T_IMPORT
|
||||
#define T_COLLATE_API T_IMPORT
|
||||
#define T_FORMAT_API T_IMPORT
|
||||
#define T_FINDWORD_API T_IMPORT
|
||||
#endif
|
||||
|
||||
/*=====================================================================================*/
|
||||
/* ErrorCode */
|
||||
/*=====================================================================================*/
|
||||
|
||||
/** Error code to replace exception handling */
|
||||
enum _ErrorCode {
|
||||
ZERO_ERROR = 0,
|
||||
ILLEGAL_ARGUMENT_ERROR, /* Start of codes indicating failure */
|
||||
MISSING_RESOURCE_ERROR,
|
||||
INVALID_FORMAT_ERROR,
|
||||
FILE_ACCESS_ERROR,
|
||||
INTERNAL_PROGRAM_ERROR, /* Indicates a bug in the library code */
|
||||
MESSAGE_PARSE_ERROR,
|
||||
MEMORY_ALLOCATION_ERROR, /* Memory allocation error */
|
||||
INDEX_OUTOFBOUNDS_ERROR,
|
||||
PARSE_ERROR, /* Equivalent to Java ParseException */
|
||||
USING_FALLBACK_ERROR = -128, /* Start of information results (semantically successful) */
|
||||
USING_DEFAULT_ERROR
|
||||
};
|
||||
|
||||
|
||||
typedef int32 ErrorCode;
|
||||
|
||||
|
||||
/* Use the following to determine if an ErrorCode represents */
|
||||
/* operational success or failure. */
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
inline t_bool SUCCESS(ErrorCode code) { return (t_bool)(code<=ZERO_ERROR); }
|
||||
inline t_bool FAILURE(ErrorCode code) { return (t_bool)(code>ZERO_ERROR); }
|
||||
#else
|
||||
#define SUCCESS(x) ((x)<=ZERO_ERROR)
|
||||
#define FAILURE(x) ((x)>ZERO_ERROR)
|
||||
#endif
|
||||
|
||||
/*=====================================================================================*/
|
||||
/* TPlatformUtilities */
|
||||
/*=====================================================================================*/
|
||||
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
/**
|
||||
* Platform utilities isolates the platform dependencies of the libarary. For
|
||||
* each platform which this code is ported to, these functions may have to
|
||||
* be re-implemented.
|
||||
*/
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
class T_UTILITY_API TPlatformUtilities
|
||||
{
|
||||
public:
|
||||
/* Floating point utilities */
|
||||
static t_bool isNaN(double);
|
||||
static t_bool isInfinite(double);
|
||||
static double getNaN();
|
||||
static double getInfinity();
|
||||
|
||||
/**
|
||||
* Time zone utilities
|
||||
*
|
||||
* Wrappers for C runtime library functions relating to timezones.
|
||||
* The t_tzset() function (similar to tzset) uses the current setting
|
||||
* of the environment variable TZ to assign values to three global
|
||||
* variables: daylight, timezone, and tzname. These variables have the
|
||||
* following meanings, and are declared in <time.h>.
|
||||
*
|
||||
* daylight Nonzero if daylight-saving-time zone (DST) is specified
|
||||
* in TZ; otherwise, 0. Default value is 1.
|
||||
* timezone Difference in seconds between coordinated universal
|
||||
* time and local time. E.g., -28,800 for PST (GMT-8hrs)
|
||||
* tzname(0) Three-letter time-zone name derived from TZ environment
|
||||
* variable. E.g., "PST".
|
||||
* tzname(1) Three-letter DST zone name derived from TZ environment
|
||||
* variable. E.g., "PDT". If DST zone is omitted from TZ,
|
||||
* tzname(1) is an empty string.
|
||||
*
|
||||
* Notes: For example, to set the TZ environment variable to correspond
|
||||
* to the current time zone in Germany, you can use one of the
|
||||
* following statements:
|
||||
*
|
||||
* set TZ=GST1GDT
|
||||
* set TZ=GST+1GDT
|
||||
*
|
||||
* If the TZ value is not set, t_tzset() attempts to use the time zone
|
||||
* information specified by the operating system. Under Windows NT
|
||||
* and Windows 95, this information is specified in the Control Panel’s
|
||||
* Date/Time application.
|
||||
*/
|
||||
static void t_tzset();
|
||||
static t_int32 t_timezone();
|
||||
static char* t_tzname(int index);
|
||||
|
||||
/* Get system time in seconds since the epoch start (GMT 1/1/70). */
|
||||
static t_int32 time();
|
||||
|
||||
/* Return the default data directory for this platform. See Locale. */
|
||||
static const char* getDefaultDataDirectory();
|
||||
|
||||
/* complete a relative path to a full pathname, and convert to platform-specific syntax. */
|
||||
/* The character seperating directories for the relative path is '|'. */
|
||||
static void pathnameInContext( char* fullname, t_int32 maxsize, char* relpath );
|
||||
|
||||
/* Return the default locale ID string by querying ths system, or
|
||||
zero if one cannot be found. */
|
||||
static const char* getDefaultLocaleID();
|
||||
|
||||
/**
|
||||
* Retrun true if this platform is big-endian, that is, if the number
|
||||
* 0x1234 is stored 0x12, 0x34 in memory. Return false if this platform
|
||||
* is little-endian, and is, if 0x1234 is stored 0x34, 0x12 in memory.
|
||||
*/
|
||||
static t_bool isBigEndian();
|
||||
|
||||
/*
|
||||
* Finds the least double greater than d (if positive == true),
|
||||
* or the greatest double less than d (if positive == false).
|
||||
* If NaN, returns same value.
|
||||
*
|
||||
* Does not affect floating-point flags,
|
||||
*/
|
||||
static double nextDouble(double d, t_bool positive);
|
||||
|
||||
inline static t_uint8 mapHostTo8859_1(t_uint8 hostChar);
|
||||
inline static t_uint8 map8859_1toHost(t_uint8 latin1char);
|
||||
|
||||
private:
|
||||
static t_bool fgIsEndianismDetermined;
|
||||
static t_bool fgIsBigEndian;
|
||||
|
||||
/**
|
||||
* Return a pointer to the top N bytes of the given double. Used
|
||||
* internally by the NaN- and Infinity-related functions.
|
||||
*/
|
||||
static char* topNBytesOfDouble(double* d, int n);
|
||||
|
||||
static t_uint8 EBCDICtoLatin1[];
|
||||
static t_uint8 Latin1toEBCDIC[];
|
||||
|
||||
};
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
inline char*
|
||||
TPlatformUtilities::topNBytesOfDouble(double* d, int n)
|
||||
{
|
||||
return TPlatformUtilities::isBigEndian() ?
|
||||
(char*)d :
|
||||
(char*)(d + 1) - n;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*=====================================================================================*/
|
||||
/* Array copy utility functions */
|
||||
/*=====================================================================================*/
|
||||
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
inline void arrayCopy(const double* src, double* dst, t_int32 count)
|
||||
{ memcpy(dst, src, (size_t)(count * sizeof(*src))); }
|
||||
|
||||
inline void arrayCopy(const double* src, t_int32 srcStart, double* dst, t_int32 dstStart, t_int32 count)
|
||||
{ memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); }
|
||||
|
||||
inline void arrayCopy(const t_bool* src, t_bool* dst, t_int32 count)
|
||||
{ memcpy(dst, src, (size_t)(count * sizeof(*src))); }
|
||||
|
||||
inline void arrayCopy(const t_bool* src, t_int32 srcStart, t_bool* dst, t_int32 dstStart, t_int32 count)
|
||||
{ memcpy(dst+dstStart, src+srcStart, (size_t)(count * sizeof(*src))); }
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* Host character set mappings */
|
||||
/* */
|
||||
/* We provide a mapping facility for 8-bit host character sets. We supply an */
|
||||
/* implementation for host EBCDIC, which we map to 8859-1 (Latin1). The source */
|
||||
/* of our data is RFC 1345; we use the charset IBM297 (aka ebcdic-cp-fr) as our */
|
||||
/* standard EBCDIC. */
|
||||
/*------------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
|
||||
inline t_uint8
|
||||
TPlatformUtilities::mapHostTo8859_1(t_uint8 hostChar)
|
||||
{
|
||||
#if USES_ISO_8859_1
|
||||
return hostChar;
|
||||
#elif USES_EBCDIC
|
||||
return EBCDICtoLatin1[hostChar];
|
||||
#endif
|
||||
}
|
||||
|
||||
inline t_uint8
|
||||
TPlatformUtilities::map8859_1toHost(t_uint8 latin1char)
|
||||
{
|
||||
#if USES_ISO_8859_1
|
||||
return latin1char;
|
||||
#elif USES_EBCDIC
|
||||
return Latin1toEBCDIC[latin1char];
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* NLS_CPLUSPLUS */
|
||||
/*=====================================================================================*/
|
||||
/* Debugging */
|
||||
/*=====================================================================================*/
|
||||
|
||||
/* This function is useful for debugging; it returns the text name */
|
||||
/* of an ErrorCode result. This is not the most efficient way of */
|
||||
/* doing this but it's just for Debug builds anyway. */
|
||||
#if defined(_DEBUG) && defined(NLS_CPLUSPLUS)
|
||||
inline const char* errorName(ErrorCode code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case ZERO_ERROR: return "ZERO_ERROR";
|
||||
case ILLEGAL_ARGUMENT_ERROR: return "ILLEGAL_ARGUMENT_ERROR";
|
||||
case MISSING_RESOURCE_ERROR: return "MISSING_RESOURCE_ERROR";
|
||||
case INVALID_FORMAT_ERROR: return "INVALID_FORMAT_ERROR";
|
||||
case FILE_ACCESS_ERROR: return "FILE_ACCESS_ERROR";
|
||||
case INTERNAL_PROGRAM_ERROR: return "INTERNAL_PROGRAM_ERROR";
|
||||
case MESSAGE_PARSE_ERROR: return "MESSAGE_PARSE_ERROR";
|
||||
case MEMORY_ALLOCATION_ERROR: return "MEMORY_ALLOCATION_ERROR";
|
||||
case USING_FALLBACK_ERROR: return "USING_FALLBACK_ERROR";
|
||||
case USING_DEFAULT_ERROR: return "USING_DEFAULT_ERROR";
|
||||
case PARSE_ERROR: return "PARSE_ERROR";
|
||||
default: return "[BOGUS ErrorCode]";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
Redefine deprecated classes.
|
||||
*/
|
||||
#ifdef NLS_CPLUSPLUS
|
||||
class Collator;
|
||||
typedef Collator Collation;
|
||||
class RuleBasedCollator;
|
||||
typedef RuleBasedCollator TableCollation;
|
||||
class CollationKey;
|
||||
typedef CollationKey SortKey;
|
||||
|
||||
class BreakIterator;
|
||||
typedef BreakIterator TextBoundary;
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,648 @@
|
|||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1996, 1997 *
|
||||
* (C) Copyright International Business Machines Corporation, 1996, 1997 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
*
|
||||
* File resbund.h
|
||||
*
|
||||
* CREATED BY
|
||||
* Richard Gillam
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 2/5/97 aliu Added scanForLocaleInFile. Added
|
||||
* constructor which attempts to read resource bundle
|
||||
* from a specific file, without searching other files.
|
||||
* 2/11/97 aliu Added ErrorCode return values to constructors. Fixed
|
||||
* infinite loops in scanForFile and scanForLocale.
|
||||
* Modified getRawResourceData to not delete storage in
|
||||
* localeData and resourceData which it doesn't own.
|
||||
* Added Mac compatibility #ifdefs for tellp() and
|
||||
* ios::nocreate.
|
||||
* 2/18/97 helena Updated with 100% documentation coverage.
|
||||
* 3/13/97 aliu Rewrote to load in entire resource bundle and store
|
||||
* it as a Hashtable of ResourceBundleData objects.
|
||||
* Added state table to govern parsing of files.
|
||||
* Modified to load locale index out of new file distinct
|
||||
* from default.txt.
|
||||
* 3/25/97 aliu Modified to support 2-d arrays, needed for timezone data.
|
||||
* Added support for custom file suffixes. Again, needed to
|
||||
* support timezone data.
|
||||
* 4/7/97 aliu Cleaned up.
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _RESBUND
|
||||
#define _RESBUND
|
||||
|
||||
#include <iostream.h>
|
||||
#include "ptypes.h"
|
||||
#include "unistring.h"
|
||||
#include "locid.h"
|
||||
class RBHashtable;
|
||||
class ResourceBundleData;
|
||||
class ResourceBundleCache;
|
||||
class VisitedFileCache;
|
||||
class Hashtable;
|
||||
|
||||
/**
|
||||
* A class representing a collection of resource information pertaining to a given
|
||||
* locale. A resource bundle provides a way of accessing locale- specfic information in
|
||||
* a data file. You create a resource bundle that manages the resources for a given
|
||||
* locale and then ask it for individual resources.
|
||||
* <P>
|
||||
* The resource bundle file is a text (ASCII or Unicode) file with the format:
|
||||
* <pre>
|
||||
* . locale {
|
||||
* . tag1 {...}
|
||||
* . tag2 {...}
|
||||
* . }
|
||||
* </pre>
|
||||
* The tags are used to retrieve the data later. You may not have multiple instances of
|
||||
* the same tag.
|
||||
* <P>
|
||||
* Four data types are supported. These are solitary strings, comma-delimited lists of
|
||||
* strings, 2-dimensional arrays of strings, and tagged lists of strings.
|
||||
* <P>
|
||||
* Note that all data is textual. Adjacent strings are merged by the low-level
|
||||
* tokenizer, so that the following effects occur: foo bar, baz // 2 elements, "foo
|
||||
* bar", and "baz" "foo" "bar", baz // 2 elements, "foobar", and "baz" Note that a
|
||||
* single intervening space is added between merged strings, unless they are both double
|
||||
* quoted. This extends to more than two strings in a row.
|
||||
* <P>
|
||||
* Whitespace is ignored, as in a C source file.
|
||||
* <P>
|
||||
* Solitary strings have the format:
|
||||
* <pre>
|
||||
* . Tag { Data }
|
||||
* </pre>
|
||||
* This is indistinguishable from a comma-delimited list with only one element, and in
|
||||
* fact may be retrieved as such (as an array, or as element 0 or an array).
|
||||
* <P>
|
||||
* Comma-delimited lists have the format:
|
||||
* <pre>
|
||||
* . Tag { Data, Data, Data }
|
||||
* </pre>
|
||||
* Parsing is lenient; a final string, after the last element, is allowed.
|
||||
* <P>
|
||||
* Tagged lists have the format:
|
||||
* <pre>
|
||||
* . Tag { Subtag { Data } Subtag {Data} }
|
||||
* </pre>
|
||||
* Data is retrieved by specifying the subtag.
|
||||
* <P>
|
||||
* Two-dimensional arrays have the format:
|
||||
* <pre>
|
||||
* . TwoD {
|
||||
* . { r1c1, r1c2, ..., r1cm },
|
||||
* . { r2c1, r2c2, ..., r2cm },
|
||||
* . ...
|
||||
* . { rnc1, rnc2, ..., rncm }
|
||||
* . }
|
||||
* </pre>
|
||||
* where n is the number of rows, and m is the number of columns. Parsing is lenient (as
|
||||
* in other data types). A final comma is always allowed after the last element; either
|
||||
* the last string in a row, or the last row itself. Furthermore, since there is no
|
||||
* ambiguity, the commas between the rows are entirely optional. (However, if a comma is
|
||||
* present, there can only be one comma, no more.) It is possible to have zero columns,
|
||||
* as follows:
|
||||
* <pre>
|
||||
* . Odd { {} {} {} } // 3 x 0 array
|
||||
* </pre>
|
||||
* But it is impossible to have zero rows. The smallest array is thus a 1 x 0 array,
|
||||
* which looks like this:
|
||||
* <pre>
|
||||
* . Smallest { {} } // 1 x 0 array
|
||||
* </pre>
|
||||
* The array must be strictly rectangular; that is, each row must have the same number
|
||||
* of elements.
|
||||
*/
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
class T_UTILITY_API ResourceBundle {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param path This is a full pathname in the platform-specific format for the
|
||||
* directory containing the resource data files we want to load
|
||||
* resources from. We use locale IDs to generate filenames, and the
|
||||
* filenames have this string prepended to them before being passed
|
||||
* to the C++ I/O functions. Therefore, this string must always end
|
||||
* with a directory delimiter (whatever that is for the target OS)
|
||||
* for this class to work correctly.
|
||||
* @param locale This is the locale this resource bundle is for. To get resources
|
||||
* for the French locale, for example, you would create a
|
||||
* ResourceBundle passing Locale::FRENCH for the "locale" parameter,
|
||||
* and all subsequent calls to that resource bundle will return
|
||||
* resources that pertain to the French locale. If the caller doesn't
|
||||
* pass a locale parameter, the default locale for the system (as
|
||||
* returned by Locale::getDefault()) will be used.
|
||||
* @param suffix If not specified, the suffix is kDefaultSuffix, that is, ".txt".
|
||||
* The caller may also specify a suffix explicitly, in which case
|
||||
* files with that suffix will be read instead.
|
||||
*
|
||||
* The ErrorCode& err parameter is used to return status information to the user. To
|
||||
* check whether the construction succeeded or not, you should check the value of
|
||||
* SUCCESS(err). If you wish more detailed information, you can check for
|
||||
* informational error results which still indicate success. USING_FALLBACK_ERROR
|
||||
* indicates that a fall back locale was used. For example, 'de_CH' was requested,
|
||||
* but nothing was found there, so 'de' was used. USING_DEFAULT_ERROR indicates that
|
||||
* the default locale data was used; neither the requested locale nor any of its
|
||||
* fall back locales could be found.
|
||||
*/
|
||||
ResourceBundle( const UnicodeString& path,
|
||||
const Locale& locale,
|
||||
ErrorCode& err);
|
||||
ResourceBundle( const UnicodeString& path,
|
||||
ErrorCode& err);
|
||||
ResourceBundle( const UnicodeString& path,
|
||||
const Locale& locale,
|
||||
const char* suffix,
|
||||
ErrorCode& err);
|
||||
ResourceBundle( const UnicodeString& path,
|
||||
const char* suffix,
|
||||
ErrorCode& err);
|
||||
~ResourceBundle();
|
||||
|
||||
/**
|
||||
* Returns the contents of a string resource. Resource data is undifferentiated
|
||||
* Unicode text. The resource file may contain quoted strings or escape sequences;
|
||||
* these will be parsed prior to the data's return.
|
||||
*
|
||||
* @param resourceTag The resource tag of the string resource the caller wants
|
||||
* @param theString Receives the actual data in the resource
|
||||
* @param err Set to MISSING_RESOURCE_ERROR if a resource with the
|
||||
* specified tag couldn't be found.
|
||||
*/
|
||||
void getString( const UnicodeString& resourceTag,
|
||||
UnicodeString& theString,
|
||||
ErrorCode& err) const;
|
||||
|
||||
/**
|
||||
* Returns the contents of a string-array resource. This will return the contents of
|
||||
* a string-array (comma-delimited-list) resource as a C++ array of UnicodeString
|
||||
* objects. The number of elements in the array is returned in numArrayItems.
|
||||
* Calling getStringArray on a resource of type string will return an array with one
|
||||
* element; calling it on a resource of type tagged-array results in a
|
||||
* MISSING_RESOURCE_ERROR error.
|
||||
*
|
||||
* @param resourceTag The resource tag of the string-array resource the caller
|
||||
* wants
|
||||
* @param numArrayItems Receives the number of items in the array the function
|
||||
* returns.
|
||||
* @param err Set to MISSING_RESOURCE_ERROR if a resource with the
|
||||
* specified tag couldn't be found.
|
||||
* @return The resource requested, as a pointer to an array of
|
||||
* UnicodeStrings. The caller does not own the storage and
|
||||
* must not delete it.
|
||||
*/
|
||||
const UnicodeString* getStringArray( const UnicodeString& resourceTag,
|
||||
t_int32& numArrayItems,
|
||||
ErrorCode& err) const;
|
||||
|
||||
/**
|
||||
* Returns a single item from a string-array resource. This will return the contents
|
||||
* of a single item in a resource of string-array (comma-delimited-list) type. If
|
||||
* the resource is not an array, a MISSING_RESOURCE_ERROR will be returned in err.
|
||||
*
|
||||
* @param resourceTag The resource tag of the resource the caller wants to extract
|
||||
* an item from.
|
||||
* @param index The index (zero-based) of the particular array item the user
|
||||
* wants to extract from the resource.
|
||||
* @param theArrayItem Receives the actual text of the desired array item.
|
||||
* @param err Set to MISSING_RESOURCE_ERROR if a resource with the
|
||||
* specified tag couldn't be found, or if the index was out of range.
|
||||
*/
|
||||
void getArrayItem( const UnicodeString& resourceTag,
|
||||
t_int32 index,
|
||||
UnicodeString& theArrayItem,
|
||||
ErrorCode& err) const;
|
||||
|
||||
/**
|
||||
* Return the contents of a 2-dimensional array resource. The return value will be a
|
||||
* UnicodeString** array. (This is really an array of pointers; each pointer is a
|
||||
* ROW of the data.) The number of rows and columns is returned. If the resource is
|
||||
* of the wrong type, or not present, MISSING_RESOURCE_ERROR is placed in err.
|
||||
*
|
||||
* @param resourceTag The resource tag of the string-array resource the caller
|
||||
* wants
|
||||
* @param rowCount Receives the number of rows in the array the function
|
||||
* returns.
|
||||
* @param columnCount Receives the number of columns in the array the function
|
||||
* returns.
|
||||
* @param err Set to MISSING_RESOURCE_ERROR if a resource with the
|
||||
* specified tag couldn't be found.
|
||||
* @return The resource requested, as a UnicodeStrings**. The caller
|
||||
* does not own the storage and must not delete it.
|
||||
*/
|
||||
const UnicodeString** get2dArray(const UnicodeString& resourceTag,
|
||||
t_int32& rowCount,
|
||||
t_int32& columnCount,
|
||||
ErrorCode& err) const;
|
||||
|
||||
/**
|
||||
* Return a single string from a 2-dimensional array resource. If the resource does
|
||||
* not exists, or if it is not a 2-d array, or if the row or column indices are out
|
||||
* of bounds, err is set to MISSING_RESOURCE_ERROR.
|
||||
*
|
||||
* @param resourceTag The resource tag of the resource the caller wants to extract
|
||||
* an item from.
|
||||
* @param rowIndex The row index (zero-based) of the array item the user wants
|
||||
* to extract from the resource.
|
||||
* @param columnIndex The column index (zero-based) of the array item the user
|
||||
* wants to extract from the resource.
|
||||
* @param theArrayItem Receives the actual text of the desired array item.
|
||||
* @param err Set to MISSING_RESOURCE_ERROR if a resource with the
|
||||
* specified tag couldn't be found, if the resource data was in
|
||||
* the wrong format, or if either index is out of bounds.
|
||||
*/
|
||||
void get2dArrayItem(const UnicodeString& resourceTag,
|
||||
t_int32 rowIndex,
|
||||
t_int32 columnIndex,
|
||||
UnicodeString& theArrayItem,
|
||||
ErrorCode& err) const;
|
||||
|
||||
/**
|
||||
* Returns a single item from a tagged-array resource This will return the contents
|
||||
* of a single item in a resource of type tagged-array. If this function is called
|
||||
* for a resource that is not of type tagged-array, it will set err to
|
||||
* MISSING_RESOUCE_ERROR.
|
||||
*
|
||||
* @param resourceTag The resource tag of the resource the caller wants to extract
|
||||
* an item from.
|
||||
* @param itemTag The item tag for the item the caller wants to extract.
|
||||
* @param theArrayItem Receives the text of the desired array item.
|
||||
* @param err Set to MISSING_RESOURCE_ERROR if a resource with the
|
||||
* specified resource tag couldn't be found, or if an item
|
||||
* with the specified item tag coldn't be found in the resource.
|
||||
*/
|
||||
void getTaggedArrayItem( const UnicodeString& resourceTag,
|
||||
const UnicodeString& itemTag,
|
||||
UnicodeString& theArrayItem,
|
||||
ErrorCode& err) const;
|
||||
|
||||
/**
|
||||
* Returns a tagged-array resource. The contents of the resource is returned as two
|
||||
* separate arrays of UnicodeStrings, the addresses of which are placed in "itemTags"
|
||||
* and "items". After calling this function, the items in the resource will be in the
|
||||
* list pointed to by "items", and for each items[i], itemTags[i] will be the tag that
|
||||
* corresponds to it. The total number of entries in both arrays is returned in
|
||||
* numItems.
|
||||
*
|
||||
* @param resourceTag The resource tag of the resource the caller wants to extract
|
||||
* an item from.
|
||||
* @param itemTags Set to point to an array of UnicodeStrings representing the
|
||||
* tags in the specified resource. The caller DOES own this array,
|
||||
* and must delete it.
|
||||
* @param items Set to point to an array of UnicodeStrings containing the
|
||||
* individual resource items themselves. itemTags[i] will
|
||||
* contain the tag corresponding to items[i]. The caller DOES
|
||||
* own this array, and must delete it.
|
||||
* @param numItems Receives the number of items in the arrays pointed to by
|
||||
* items and itemTags.
|
||||
* @param err Set to MISSING_RESOURCE_ERROR if a resource with the
|
||||
* specified tag couldn't be found.
|
||||
*/
|
||||
void getTaggedArray( const UnicodeString& resourceTag,
|
||||
UnicodeString*& itemTags,
|
||||
UnicodeString*& items,
|
||||
t_int32& numItems,
|
||||
ErrorCode& err) const;
|
||||
/**
|
||||
* Return the version number associated with this ResourceBundle. This version
|
||||
* number is a string of the form MAJOR.MINOR, where MAJOR is the version number of
|
||||
* the current analytic code package, and MINOR is the version number contained in
|
||||
* the resource file as the value of the tag "Version". A change in the MINOR
|
||||
* version indicated an updated data file. A change in the MAJOR version indicates a
|
||||
* new version of the code which is not binary-compatible with the previous version.
|
||||
* If no "Version" tag is present in a resource file, the MINOR version "0" is assigned.
|
||||
*
|
||||
* For example, if the Collation sort key algorithm changes, the MAJOR version
|
||||
* increments. If the collation data in a resource file changes, the MINOR version
|
||||
* for that file increments.
|
||||
*
|
||||
* @return A string of the form N.n, where N is the major version number,
|
||||
* representing the code version, and n is the minor version number,
|
||||
* representing the resource data file. The caller does not own this
|
||||
* string.
|
||||
*/
|
||||
const char* getVersionNumber();
|
||||
|
||||
private:
|
||||
friend class Locale;
|
||||
friend class RuleBasedCollator;
|
||||
|
||||
/**
|
||||
* This constructor is used by Collation to load a resource bundle from a specific
|
||||
* file, without trying other files. This is used by the Collation caching
|
||||
* mechanism.
|
||||
*/
|
||||
ResourceBundle( const UnicodeString& path,
|
||||
const UnicodeString& localeName,
|
||||
const char* suffix,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Return a list of all installed locales. This function returns a list of the IDs
|
||||
* of all locales represented in the directory specified by this ResourceBundle. It
|
||||
* depends on that directory having an "Index" tagged-list item in its "index.txt"
|
||||
* file; it parses that list to determine its return value (therefore, that list
|
||||
* also has to be up to date). This function is static.
|
||||
*
|
||||
* This function is the implementation of the Locale::listInstalledLocales()
|
||||
* function. It's private because the API for it real;ly belongs in Locale.
|
||||
*
|
||||
* @param path The path to the locale data files. The function will
|
||||
* look here for "index.txt".
|
||||
* @param numInstalledLocales Receives the number of installed locales, according
|
||||
* to the Index resource in index.txt.
|
||||
* @return A list of the installed locales, as a pointer to an
|
||||
* array of UnicodeStrings. This storage is not owned by
|
||||
* the caller, who must not delete it. The information
|
||||
* in this list is derived from the Index resource in
|
||||
* default.txt, which must be kept up to date.
|
||||
*/
|
||||
static const UnicodeString* listInstalledLocales(const UnicodeString& path,
|
||||
t_int32& numInstalledLocales);
|
||||
|
||||
/**
|
||||
* Construct a file name by concatenating together the three given elements and
|
||||
* returning the result as a CharString. No separators are interposed.
|
||||
*/
|
||||
static char* createFilename( const UnicodeString& prefix,
|
||||
const UnicodeString& name,
|
||||
const UnicodeString& suffix);
|
||||
|
||||
/**
|
||||
* Retrieve a ResourceBundle from the cache. Return NULL if not found.
|
||||
*/
|
||||
static const Hashtable* getFromCache(const UnicodeString& path,
|
||||
const UnicodeString& localeName,
|
||||
const UnicodeString& suffix);
|
||||
|
||||
static const Hashtable* getFromCacheWithFallback(const UnicodeString& path,
|
||||
const UnicodeString& desiredLocale,
|
||||
UnicodeString& returnedLocale,
|
||||
const UnicodeString& suffix,
|
||||
ErrorCode& error);
|
||||
|
||||
/**
|
||||
* Construct a string key for this object, based on the path name and the locale.
|
||||
*/
|
||||
static void makeHashkey(UnicodeString& keyName,
|
||||
const UnicodeString& path,
|
||||
const UnicodeString& localeName,
|
||||
const UnicodeString& suffix);
|
||||
|
||||
/**
|
||||
* Handlers which are passed to parse() have this signature.
|
||||
*/
|
||||
typedef void (*Handler)(const UnicodeString& localeName,
|
||||
Hashtable* hashtable,
|
||||
void* context);
|
||||
|
||||
/**
|
||||
* Parse a file, storing the resource data in the cache.
|
||||
*/
|
||||
static void parse(const char* filename,
|
||||
Handler handler,
|
||||
void* context,
|
||||
ErrorCode &error);
|
||||
|
||||
/**
|
||||
* If the given file exists and has not been parsed, then parse it (caching the
|
||||
* resultant data) and return true.
|
||||
*/
|
||||
static t_bool parseIfUnparsed(const UnicodeString& path,
|
||||
const UnicodeString& locale,
|
||||
const UnicodeString& suffix,
|
||||
ErrorCode& error);
|
||||
|
||||
const Hashtable* getHashtableForLocale(const UnicodeString& localeName,
|
||||
UnicodeString& returnedLocale,
|
||||
ErrorCode& err);
|
||||
|
||||
const Hashtable* getHashtableForLocale(const UnicodeString& desiredLocale,
|
||||
ErrorCode& error);
|
||||
|
||||
const ResourceBundleData* getDataForTag(const UnicodeString& tag,
|
||||
ErrorCode& err) const;
|
||||
|
||||
void constructForLocale(const UnicodeString& path,
|
||||
const Locale& locale,
|
||||
const char* suffix,
|
||||
ErrorCode& error);
|
||||
|
||||
struct AddToCacheContext
|
||||
{
|
||||
const UnicodeString* fPath;
|
||||
const UnicodeString* fFilenameSuffix;
|
||||
};
|
||||
|
||||
static void addToCache(const UnicodeString& localeName,
|
||||
Hashtable* hashtable,
|
||||
void* context);
|
||||
|
||||
static void saveCollationHashtable(const UnicodeString& localeName,
|
||||
Hashtable* hashtable,
|
||||
void* context);
|
||||
private:
|
||||
/**
|
||||
* This internal class iterates over the fallback and/or default locales. It
|
||||
* progresses as follows: Specific: language+country+variant language+country
|
||||
* language Default: language+country+variant language+country language Root:
|
||||
*/
|
||||
class LocaleFallbackIterator
|
||||
{
|
||||
public:
|
||||
LocaleFallbackIterator(const UnicodeString& startingLocale,
|
||||
const UnicodeString& root,
|
||||
t_bool useDefaultLocale);
|
||||
|
||||
const UnicodeString& getLocale() const { return fLocale; }
|
||||
|
||||
t_bool nextLocale(ErrorCode& status);
|
||||
|
||||
private:
|
||||
void chopLocale();
|
||||
|
||||
UnicodeString fLocale;
|
||||
UnicodeString fDefaultLocale;
|
||||
UnicodeString fRoot;
|
||||
t_bool fUseDefaultLocale;
|
||||
t_bool fTriedDefaultLocale;
|
||||
t_bool fTriedRoot;
|
||||
};
|
||||
|
||||
private:
|
||||
/**
|
||||
* Node IDs for the state transition table. These must fit into 8 bits, as specified
|
||||
* by kNodeMask. They must not overlap the bit range used by EAction.
|
||||
*/
|
||||
public: // Not really public; just to allow inner class below to compile
|
||||
enum ENode
|
||||
{
|
||||
/*0*/ kError,
|
||||
/*1*/ kInitial, // Next: Locale name
|
||||
/*2*/ kGotLoc, // Next: {
|
||||
/*3*/ kIdle, // Next: Tag name | }
|
||||
/*4*/ kGotTag, // Next: {
|
||||
/*5*/ kNode5, // Next: Data | Subtag
|
||||
/*6*/ kNode6, // Next: } | { | ,
|
||||
/*7*/ kList, // Next: List data
|
||||
/*8*/ kNode8, // Next: ,
|
||||
/*9*/ kTagList, // Next: Subtag data
|
||||
/*10*/ kNode10, // Next: }
|
||||
/*11*/ kNode11, // Next: Subtag
|
||||
/*12*/ kNode12, // Next: {
|
||||
/*13*/ k2dArray, // Next: Data | }
|
||||
/*14*/ kNode14, // Next: , | }
|
||||
/*15*/ kNode15, // Next: , | }
|
||||
/*16*/ kNode16, // Next: { | }
|
||||
kNodeCount,
|
||||
kNodeMask = 0x00FF
|
||||
};
|
||||
private:
|
||||
|
||||
/**
|
||||
* Action codes for the state transtiion table. These must fit into 8 bits, as
|
||||
* specified by kActionMask, and must not overlap the bit range used by ENode. We
|
||||
* may move these to being bitmasks (i.e., 0x0100, 0x0200, 0x0400, etc.) in the
|
||||
* future if we want to assign multiple actions to a single transition.
|
||||
*/
|
||||
public: // Not really public; just to allow inner class below to compile
|
||||
enum EAction
|
||||
{
|
||||
// Generic actions
|
||||
kNOP =0x0100, // Do nothing
|
||||
kOpen =0x0200, // Open a new locale data block with the data string as the locale name
|
||||
kClose =0x0300, // Close a locale data block
|
||||
kSetTag =0x0400, // Record the last string as the tag name
|
||||
|
||||
// Comma-delimited lists
|
||||
kBegList =0x1100, // Start a new string list with the last string as the first element
|
||||
kEndList =0x1200, // Close a string list being built
|
||||
kListStr =0x1300, // Record the last string as a data string and increment the index
|
||||
kStr =0x1400, // Record the last string as a singleton string
|
||||
|
||||
// 2-d lists
|
||||
kBeg2dList =0x2100, // Start a new 2d string list with no elements as yet
|
||||
kEnd2dList =0x2200, // Close a 2d string list being built
|
||||
k2dStr =0x2300, // Record the last string as a 2d string
|
||||
kNewRow =0x2400, // Start a new row
|
||||
|
||||
// Tagged lists
|
||||
kBegTagged =0x3100, // Start a new tagged list with the last string as the first subtag
|
||||
kEndTagged =0x3200, // Close a tagged list being build
|
||||
kSubtag =0x3300, // Record the last string as the subtag
|
||||
kTaggedStr =0x3400, // Record the last string as a tagged string
|
||||
|
||||
kActionMask =0xFF00
|
||||
};
|
||||
|
||||
/**
|
||||
* A convenience class which encapsulates a node ID and an action. Really just a
|
||||
* struct with constructors.
|
||||
*/
|
||||
class T_UTILITY_API Transition
|
||||
{
|
||||
public:
|
||||
Transition(); // must have a default constructor for HPUX
|
||||
Transition(ENode n);
|
||||
Transition(const int i); // int will be split into ENode and EAction
|
||||
ENode fNext;
|
||||
EAction fAction;
|
||||
};
|
||||
friend class Transition;
|
||||
|
||||
private:
|
||||
/**
|
||||
* This table describes an ATM (state machine) which parses resource bundle text
|
||||
* files rather strictly. Each row represents a node. The columns of that row
|
||||
* represent transitions into other nodes. Most transitions are "kError" because
|
||||
* most transitions are disallowed. For example, if the parser has just seen a tag
|
||||
* name, it enters node 4 ("kGotTag"). The state table then marks only one valid
|
||||
* transition, which is into node 5, upon seeing a kOpenBrace token.
|
||||
*
|
||||
* Some of the transitions are ORed with another value. This second value encodes
|
||||
* actions to be taken with the transition. The action values and the node IDs
|
||||
* occupy mutually exclusive bit ranges in a 16-bit word. Actions occupy the upper 8
|
||||
* bits; node IDs occupy the lower 8 bits. This allows us to OR them together to get
|
||||
* a composite transition/action value.
|
||||
*
|
||||
* We allow an extra comma after the last element in a comma-delimited list
|
||||
* (transition from kList to kIdle on kCloseBrace).
|
||||
*/
|
||||
static Transition kTransitionTable[];
|
||||
|
||||
/**
|
||||
* Retrieve an element from the transition table.
|
||||
* [The type of "col" should actually be ResourceFormatReader::ETokenType, but we
|
||||
* declare it short here to avoid exposing ResourceFormatReader to the world.]
|
||||
*/
|
||||
static Transition& getTransition(ENode row, short col);
|
||||
|
||||
public:
|
||||
#ifdef _DEBUG
|
||||
// This is used for debugging
|
||||
friend ostream& operator<<(ostream&, const ResourceBundle&);
|
||||
#endif
|
||||
|
||||
private:
|
||||
static const char* kDefaultSuffix;
|
||||
static const char* kDefaultFilename;
|
||||
static const char* kDefaultLocaleName;
|
||||
static const char* kIndexLocaleName;
|
||||
static const char* kIndexFilename;
|
||||
static const char* kIndexTag;
|
||||
static const UniChar kSeparator;
|
||||
|
||||
static const char* kDefaultMinorVersion;
|
||||
static const char* kVersionSeparator;
|
||||
static const UnicodeString kVersionTag;
|
||||
|
||||
static ResourceBundleCache* fgCache;
|
||||
static VisitedFileCache* fgVisitedFiles;
|
||||
|
||||
/**
|
||||
* Data members. The ResourceBundle object is kept lightweight by having the fData[]
|
||||
* array entries be non-owned pointers. The cache (fgCache) owns the entries and
|
||||
* will delete them at static destruction time.
|
||||
*/
|
||||
UnicodeString fPath;
|
||||
UnicodeString fFilenameSuffix;
|
||||
|
||||
enum { kDataCount = 4 };
|
||||
const Hashtable* fData[kDataCount]; // These aren't const if fIsDataOwned is true
|
||||
t_bool fLoaded[kDataCount];
|
||||
t_bool fIsDataOwned;
|
||||
UnicodeString fRealLocaleID;
|
||||
LocaleFallbackIterator* fLocaleIterator;
|
||||
char* fVersionID;
|
||||
};
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
inline ResourceBundle::Transition&
|
||||
ResourceBundle::getTransition(ENode row,
|
||||
short col)
|
||||
{
|
||||
// Row length is 4
|
||||
return kTransitionTable[col + (row<<2)];
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
(C) Copyright Taligent, Inc. 1996 - All Rights Reserved
|
||||
(C) Copyright IBM Corp. 1996 - All Rights Reserved
|
||||
|
||||
The original version of this source code and documentation is copyrighted and
|
||||
owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These materials are
|
||||
provided under terms of a License Agreement between Taligent and Sun. This
|
||||
technology is protected by multiple US and International patents. This notice and
|
||||
attribution to Taligent may not be removed.
|
||||
Taligent is a registered trademark of Taligent, Inc.
|
||||
*/
|
||||
|
||||
#include "ptypes.h"
|
||||
#include "chariter.h"
|
||||
|
||||
/**
|
||||
* A concrete subclass of CharacterIterator that iterates over the characters in
|
||||
* a UnicodeString. It's possible not only to create an iterator that iterates over
|
||||
* an entire UnicodeString, but also to create only that iterates over only a subrange
|
||||
* of a UnicodeString (iterators over different subranges of the same UnicodeString
|
||||
* don't compare equal).
|
||||
*/
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
class T_UTILITY_API StringCharacterIterator : public CharacterIterator {
|
||||
public:
|
||||
/**
|
||||
* Create an iterator over the UnicodeString referred to by "text".
|
||||
* The iteration range is the whole string, and the starting position is 0.
|
||||
*/
|
||||
StringCharacterIterator(const UnicodeString& text);
|
||||
|
||||
/**
|
||||
* Create an iterator over the UnicodeString referred to by "text".
|
||||
* The iteration range is the whole string, and the starting position is
|
||||
* specified by "pos". If "pos" is outside the valid iteration range, the
|
||||
* behavior of this object is undefined.
|
||||
*/
|
||||
StringCharacterIterator(const UnicodeString& text,
|
||||
TextOffset pos);
|
||||
|
||||
/**
|
||||
* Create an iterator over the UnicodeString referred to by "text".
|
||||
* The iteration range begins with the character specified by "begin" and
|
||||
* ends with the character BEFORE the character specfied by "end". The
|
||||
* starting position is specified by "pos". If "begin" and "end" don't form
|
||||
* a valid range on "text" (i.e., begin >= end or either is negative or
|
||||
* greater than text.size()), or "pos" is outside the range defined by "begin"
|
||||
* and "end", the behavior of this iterator is undefined.
|
||||
*/
|
||||
StringCharacterIterator(const UnicodeString& text,
|
||||
TextOffset begin,
|
||||
TextOffset end,
|
||||
TextOffset pos);
|
||||
|
||||
/**
|
||||
* Copy constructor. The new iterator iterates over the same range of the same
|
||||
* string as "that", and its initial position is the same as "that"'s current
|
||||
* position.
|
||||
*/
|
||||
StringCharacterIterator(const StringCharacterIterator& that);
|
||||
/**
|
||||
* Assignment operator. *this is altered to iterate over the sane range of the
|
||||
* same string as "that", and refers to the same character within that string
|
||||
* as "that" does.
|
||||
*/
|
||||
StringCharacterIterator&
|
||||
operator=(const StringCharacterIterator& that);
|
||||
|
||||
/**
|
||||
* Returns true if the iterators iterate over the same range of the same
|
||||
* string and are pointing at the same character.
|
||||
*/
|
||||
virtual t_bool operator==(const CharacterIterator& that) const;
|
||||
|
||||
/**
|
||||
* Generates a hash code for this iterator.
|
||||
*/
|
||||
virtual t_int32 hashCode() const;
|
||||
|
||||
/**
|
||||
* Returns a new StringCharacterIterator referring to the same character in the
|
||||
* same range of the same string as this one. The caller must delete the new
|
||||
* iterator.
|
||||
*/
|
||||
virtual CharacterIterator* clone() const;
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the first character in its iteration range, and
|
||||
* returns that character,
|
||||
*/
|
||||
virtual UniChar first();
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the last character in its iteration range, and
|
||||
* returns that character.
|
||||
*/
|
||||
virtual UniChar last();
|
||||
|
||||
/**
|
||||
* Sets the iterator to refer to the "position"-th character in the UnicodeString
|
||||
* the iterator refers to, and returns that character. If the index is outside
|
||||
* the iterator's iteration range, the behavior of the iterator is undefined.
|
||||
*/
|
||||
virtual UniChar setIndex(TextOffset pos);
|
||||
|
||||
/**
|
||||
* Returns the character the iterator currently refers to.
|
||||
*/
|
||||
virtual UniChar current() const;
|
||||
|
||||
/**
|
||||
* Advances to the next character in the iteration range (toward last()), and
|
||||
* returns that character. If there are no more characters to return, returns DONE.
|
||||
*/
|
||||
virtual UniChar next();
|
||||
|
||||
/**
|
||||
* Advances to the previous character in the iteration rance (toward first()), and
|
||||
* returns that character. If there are no more characters to return, returns DONE.
|
||||
*/
|
||||
virtual UniChar previous();
|
||||
|
||||
/**
|
||||
* Returns the numeric index of the first character in this iterator's iteration
|
||||
* range.
|
||||
*/
|
||||
virtual TextOffset startIndex() const;
|
||||
|
||||
/**
|
||||
* Returns the numeric index of the character immediately BEYOND the last character
|
||||
* in this iterator's iteration range.
|
||||
*/
|
||||
virtual TextOffset endIndex() const;
|
||||
|
||||
/**
|
||||
* Returns the numeric index in the underlying UnicodeString of the character
|
||||
* the iterator currently refers to (i.e., the character returned by current()).
|
||||
*/
|
||||
virtual TextOffset getIndex() const;
|
||||
|
||||
/**
|
||||
* Copies the UnicodeString under iteration into the UnicodeString referred to by
|
||||
* "result". Even if this iterator iterates across only a part of this string,
|
||||
* the whole string is copied.
|
||||
* @param result Receives a copy of the text under iteration.
|
||||
*/
|
||||
virtual void getText(UnicodeString& result);
|
||||
|
||||
/**
|
||||
* Return a class ID for this object (not really public)
|
||||
*/
|
||||
virtual ClassID getDynamicClassID() const { return getStaticClassID(); }
|
||||
|
||||
/**
|
||||
* Return a class ID for this class (not really public)
|
||||
*/
|
||||
static ClassID getStaticClassID() { return (ClassID)(&fgClassID); }
|
||||
|
||||
private:
|
||||
StringCharacterIterator();
|
||||
|
||||
const UnicodeString* text;
|
||||
TextOffset pos;
|
||||
TextOffset begin;
|
||||
TextOffset end;
|
||||
|
||||
static char fgClassID;
|
||||
};
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
|
@ -0,0 +1,362 @@
|
|||
/*
|
||||
********************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1997 *
|
||||
* (C) Copyright International Business Machines Corporation, 1997 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
********************************************************************************
|
||||
*
|
||||
* File SIMPLETZ.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 04/21/97 aliu Overhauled header.
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _SIMPLETZ
|
||||
#define _SIMPLETZ
|
||||
|
||||
#include "timezone.h"
|
||||
|
||||
/**
|
||||
* <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code>
|
||||
* that represents a time zone for use with a Gregorian calendar. This
|
||||
* class does not handle historical changes.
|
||||
* <P>
|
||||
* When specifying daylight-savings-time begin and end dates, use a negative value for
|
||||
* <code>dayOfWeekInMonth</code> to indicate that <code>SimpleTimeZone</code> should
|
||||
* count from the end of the month backwards. For example, in the U.S., Daylight Savings
|
||||
* Time ends at the last (dayOfWeekInMonth = -1) Sunday in October, at 2 AM in standard
|
||||
* time.
|
||||
*
|
||||
* @see Calendar
|
||||
* @see GregorianCalendar
|
||||
* @see TimeZone
|
||||
* @version 1.24 10/30/97
|
||||
* @author David Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
|
||||
*/
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
class T_FORMAT_API SimpleTimeZone: public TimeZone {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Need default constructor for some UNIX platforms
|
||||
*/
|
||||
SimpleTimeZone(void);
|
||||
/**
|
||||
* Copy constructor
|
||||
*/
|
||||
SimpleTimeZone(const SimpleTimeZone& source);
|
||||
|
||||
/**
|
||||
* Default assignment operator
|
||||
*/
|
||||
SimpleTimeZone& operator=(const SimpleTimeZone& right);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~SimpleTimeZone();
|
||||
|
||||
/**
|
||||
* Returns true if the two TimeZone objects are equal; that is, they have
|
||||
* the same ID, raw GMT offset, and DST rules.
|
||||
*
|
||||
* @param that The SimpleTimeZone object to be compared with.
|
||||
* @return True if the given time zone is equal to this time zone; false
|
||||
* otherwise.
|
||||
*/
|
||||
virtual t_bool operator==(const TimeZone& that) const;
|
||||
|
||||
/**
|
||||
* Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID,
|
||||
* and which doesn't observe daylight savings time. Normally you should use
|
||||
* TimeZone::createInstance() to create a TimeZone instead of creating a
|
||||
* SimpleTimeZone directly with this constructor.
|
||||
*
|
||||
* @param rawOffset The given base time zone offset to GMT.
|
||||
* @param ID The timezone ID which is obtained from
|
||||
* TimeZone.getAvailableIDs.
|
||||
*/
|
||||
SimpleTimeZone(t_int32 rawOffset, const UnicodeString& ID);
|
||||
|
||||
/**
|
||||
* Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
|
||||
* and times to start and end daylight savings time. To create a TimeZone that
|
||||
* doesn't observe daylight savings time, don't use this constructor; use
|
||||
* SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
|
||||
* TimeZone.createInstance() to create a TimeZone instead of creating a
|
||||
* SimpleTimeZone directly with this constructor.
|
||||
* <P>
|
||||
* Various types of daylight-savings time rules can be specfied by using different
|
||||
* values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a
|
||||
* complete explanation of how these parameters work, see the documentation for
|
||||
* setStartRule().
|
||||
*
|
||||
* @param rawOffset The new SimpleTimeZone's raw GMT offset
|
||||
* @param ID The new SimpleTimeZone's time zone ID.
|
||||
* @param startMonth The daylight savings starting month. Month is
|
||||
* 0-based. eg, 0 for January.
|
||||
* @param startDay The daylight savings starting
|
||||
* day-of-week-in-month. See setStartRule() for a
|
||||
* complete explanation.
|
||||
* @param startDayOfWeek The daylight savings starting day-of-week. See setStartRule()
|
||||
* for a complete explanation.
|
||||
* @param startTime The daylight savings starting time, expressed as the
|
||||
* number of milliseconds after midnight.
|
||||
* @param endMonth The daylight savings ending month. Month is
|
||||
* 0-based. eg, 0 for January.
|
||||
* @param endDay The daylight savings ending day-of-week-in-month.
|
||||
* See setStartRule() for a complete explanation.
|
||||
* @param endDayOfWeek The daylight savings ending day-of-week. See setStartRule()
|
||||
* for a complete explanation.
|
||||
* @param endTime The daylight savings ending time, expressed as the
|
||||
* number of milliseconds after midnight.
|
||||
* @param dstSavings The number of milliseconds to add to the raw GMT offset
|
||||
* when daylight savings time is in effect. (e.g., in the
|
||||
* U.S. daylight savings time shifts the time forward one
|
||||
* hour.) Defaults to plus one hour.
|
||||
*/
|
||||
SimpleTimeZone(t_int32 rawOffset, const UnicodeString& ID,
|
||||
t_int8 startMonth, t_int8 startDayOfWeekInMonth,
|
||||
t_int8 startDayOfWeek, t_int32 startTime,
|
||||
t_int8 endMonth, t_int8 endDayOfWeekInMonth,
|
||||
t_int8 endDayOfWeek, t_int32 endTime,
|
||||
t_int32 dstSavings = kMillisPerHour);
|
||||
|
||||
/**
|
||||
* Sets the daylight savings starting year, that is, the year this time zone began
|
||||
* observing its specified daylight savings time rules. The time zone is considered
|
||||
* not to observe daylight savings time prior to that year; SimpleTimeZone doesn't
|
||||
* support historical daylight-savings-time rules.
|
||||
* @param year the daylight savings starting year.
|
||||
*/
|
||||
void setStartYear(t_int32 year);
|
||||
|
||||
/**
|
||||
* Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
|
||||
* Time starts at the first Sunday in April, at 2 AM in standard time.
|
||||
* Therefore, you can set the start rule by calling:
|
||||
* setStartRule(TimeFields.APRIL, 1, TimeFields.SUNDAY, 2*60*60*1000);
|
||||
* The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
|
||||
* the exact starting date. Their exact meaning depend on their respective signs,
|
||||
* allowing various types of rules to be constructed, as follows:<ul>
|
||||
* <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
|
||||
* day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
|
||||
* of the month).
|
||||
* <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
|
||||
* the day of week in the month counting backward from the end of the month.
|
||||
* (e.g., (-1, MONDAY) is the last Monday in the month)
|
||||
* <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
|
||||
* specifies the day of the month, regardless of what day of the week it is.
|
||||
* (e.g., (10, 0) is the tenth day of the month)
|
||||
* <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
|
||||
* specifies the day of the month counting backward from the end of the
|
||||
* month, regardless of what day of the week it is (e.g., (-2, 0) is the
|
||||
* next-to-last day of the month).
|
||||
* <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
|
||||
* first specified day of the week on or after the specfied day of the month.
|
||||
* (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
|
||||
* [or the 15th itself if the 15th is a Sunday].)
|
||||
* <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
|
||||
* last specified day of the week on or before the specified day of the month.
|
||||
* (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
|
||||
* [or the 20th itself if the 20th is a Tuesday].)</ul>
|
||||
* @param month the daylight savings starting month. Month is 0-based.
|
||||
* eg, 0 for January.
|
||||
* @param dayOfWeekInMonth the daylight savings starting
|
||||
* day-of-week-in-month. Please see the member description for an example.
|
||||
* @param dayOfWeek the daylight savings starting day-of-week. Please see
|
||||
* the member description for an example.
|
||||
* @param time the daylight savings starting time. Please see the member
|
||||
* description for an example.
|
||||
*/
|
||||
void setStartRule(int month, int dayOfWeekInMonth, int dayOfWeek,
|
||||
t_int32 time);
|
||||
|
||||
/**
|
||||
* Sets the daylight savings ending rule. For example, in the U.S., Daylight
|
||||
* Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
|
||||
* Therefore, you can set the end rule by calling:
|
||||
* <pre>
|
||||
* . setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000);
|
||||
* </pre>
|
||||
* Various other types of rules can be specified by manipulating the dayOfWeek
|
||||
* and dayOfWeekInMonth parameters. For complete details, see the documentation
|
||||
* for setStartRule().
|
||||
*
|
||||
* @param month the daylight savings ending month. Month is 0-based.
|
||||
* eg, 0 for January.
|
||||
* @param dayOfWeekInMonth the daylight savings ending
|
||||
* day-of-week-in-month. See setStartRule() for a complete explanation.
|
||||
* @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
|
||||
* for a complete explanation.
|
||||
* @param time the daylight savings ending time. Please see the member
|
||||
* description for an example.
|
||||
*/
|
||||
void setEndRule(int month, int dayOfWeekInMonth, int dayOfWeek,
|
||||
t_int32 time);
|
||||
|
||||
/**
|
||||
* Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
|
||||
* to GMT to get local time in this time zone, taking daylight savings time into
|
||||
* account) as of a particular reference date. The reference date is used to determine
|
||||
* whether daylight savings time is in effect and needs to be figured into the offset
|
||||
* that is returned (in other words, what is the adjusted GMT offset in this time zone
|
||||
* at this particular date and time?).
|
||||
* <P>
|
||||
* For the time zones produced by createTimeZone(),
|
||||
* the reference data is specified according to the Gregorian calendar, and the date
|
||||
* and time fields are in GMT, NOT local time.
|
||||
*
|
||||
* @param era The reference date's era
|
||||
* @param year The reference date's year
|
||||
* @param month The reference date's month (0-based; 0 is January)
|
||||
* @param day The reference date's day-in-month (1-based)
|
||||
* @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday)
|
||||
* @param millis The reference date's milliseconds in day, UTT (NOT local time).
|
||||
* @return The offset in milliseconds to add to GMT to get local time.
|
||||
*/
|
||||
virtual t_int32 getOffset(t_uint8 era, t_int32 year, t_int32 month, t_int32 day,
|
||||
t_uint8 dayOfWeek, t_int32 millis) const;
|
||||
/**
|
||||
* Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
|
||||
* to GMT to get local time, before taking daylight savings time into account).
|
||||
*
|
||||
* @return The TimeZone's raw GMT offset.
|
||||
*/
|
||||
virtual t_int32 getRawOffset() const;
|
||||
|
||||
/**
|
||||
* Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
|
||||
* to GMT to get local time, before taking daylight savings time into account).
|
||||
*
|
||||
* @param offsetMillis The new raw GMT offset for this time zone.
|
||||
*/
|
||||
virtual void setRawOffset(t_int32 offsetMillis);
|
||||
|
||||
/**
|
||||
* Queries if this TimeZone uses Daylight Savings Time.
|
||||
*
|
||||
* @return True if this TimeZone uses Daylight Savings Time; false otherwise.
|
||||
*/
|
||||
virtual t_bool useDaylightTime() const;
|
||||
|
||||
/**
|
||||
* Returns true if the given date is within the period when daylight savings time
|
||||
* is in effect; false otherwise. If the TimeZone doesn't observe daylight savings
|
||||
* time, this functions always returns false.
|
||||
* @param date The date to test.
|
||||
* @return true if the given date is in Daylight Savings Time;
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual t_bool inDaylightTime(Date date, ErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Clones TimeZone objects polymorphically. Clients are responsible for deleting
|
||||
* the TimeZone object cloned.
|
||||
*
|
||||
* @return A new copy of this TimeZone object.
|
||||
*/
|
||||
virtual TimeZone* clone() const;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Override TimeZone Returns a unique class ID POLYMORPHICALLY. Pure virtual
|
||||
* override. This method is to implement a simple version of RTTI, since not all C++
|
||||
* compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
|
||||
* this method.
|
||||
*
|
||||
* @return The class ID for this object. All objects of a given class have the
|
||||
* same class ID. Objects of other classes have different class IDs.
|
||||
*/
|
||||
virtual ClassID getDynamicClassID() const { return (ClassID)&fgClassID; }
|
||||
|
||||
/**
|
||||
* Return the class ID for this class. This is useful only for comparing to a return
|
||||
* value from getDynamicClassID(). For example:
|
||||
* <pre>
|
||||
* . Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* . if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* . Derived::getStaticClassID()) ...
|
||||
* </pre>
|
||||
* @return The class ID for all objects of this class.
|
||||
*/
|
||||
static ClassID getStaticClassID() { return (ClassID)&fgClassID; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* Constants specifying values of startMode and endMode.
|
||||
*/
|
||||
enum EMode
|
||||
{
|
||||
DOM_MODE = 1,
|
||||
DOW_IN_MONTH_MODE,
|
||||
DOW_GE_DOM_MODE,
|
||||
DOW_LE_DOM_MODE
|
||||
};
|
||||
|
||||
/**
|
||||
* Compare a given date in the year to a rule. Return 1, 0, or -1, depending
|
||||
* on whether the date is after, equal to, or before the rule date. The
|
||||
* millis are compared directly against the ruleMillis, so any
|
||||
* standard-daylight adjustments must be handled by the caller. Assume that
|
||||
* no rule references the end of February (e.g., last Sunday in February).
|
||||
*
|
||||
* @return 1 if the date is after the rule date, -1 if the date is before
|
||||
* the rule date, or 0 if the date is equal to the rule date.
|
||||
*/
|
||||
static int compareToRule(int month, int dayOfMonth, int dayOfWeek, t_int32 millis,
|
||||
EMode ruleMode, int ruleMonth, int ruleDayOfWeek,
|
||||
int ruleDay, t_int32 ruleMillis);
|
||||
|
||||
/**
|
||||
* Given a set of encoded rules in startDay and startDayOfMonth, decode
|
||||
* them and set the startMode appropriately. Do the same for endDay and
|
||||
* endDayOfMonth.
|
||||
* <P>
|
||||
* Upon entry, the day of week variables may be zero or
|
||||
* negative, in order to indicate special modes. The day of month
|
||||
* variables may also be negative.
|
||||
* <P>
|
||||
* Upon exit, the mode variables will be
|
||||
* set, and the day of week and day of month variables will be positive.
|
||||
* <P>
|
||||
* This method also recognizes a startDay or endDay of zero as indicating
|
||||
* no DST.
|
||||
*/
|
||||
void decodeRules();
|
||||
|
||||
static char fgClassID;
|
||||
|
||||
int startMonth, startDay, startDayOfWeek; // the month, day, DOW, and time DST starts
|
||||
t_int32 startTime;
|
||||
int endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends
|
||||
t_int32 endTime;
|
||||
int startYear; // the year these DST rules took effect
|
||||
t_int32 rawOffset; // the TimeZone's raw GMT offset
|
||||
t_bool useDaylight; // flag indicating whether this TimeZone uses DST
|
||||
static t_int32 millisPerHour; // number of millis in an hour
|
||||
static const t_uint8 staticMonthLength[12]; // lengths of the months
|
||||
EMode startMode, endMode; // flags indicating what kind of rules the DST rules are
|
||||
|
||||
/**
|
||||
* A positive value indicating the amount of time saved during DST in ms.
|
||||
* Typically one hour; sometimes 30 minutes.
|
||||
*/
|
||||
t_int32 dstSavings;
|
||||
};
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
#endif // _SIMPLETZ
|
|
@ -0,0 +1,670 @@
|
|||
/*
|
||||
********************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1997 *
|
||||
* (C) Copyright International Business Machines Corporation, 1997 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
********************************************************************************
|
||||
*
|
||||
* File SMPDTFMT.H
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/19/97 aliu Converted from java.
|
||||
* 07/09/97 helena Make ParsePosition into a class.
|
||||
********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _SMPDTFMT
|
||||
#define _SMPDTFMT
|
||||
|
||||
#include "ptypes.h"
|
||||
#include "datefmt.h"
|
||||
class DateFormatSymbols;
|
||||
|
||||
/**
|
||||
* SimpleDateFormat is a concrete class for formatting and parsing dates in a
|
||||
* language-independent manner. It allows for formatting (millis -> text),
|
||||
* parsing (text -> millis), and normalization. Formats/Parses a date or time,
|
||||
* which is the standard milliseconds since 24:00 GMT, Jan 1, 1970.
|
||||
* <P>
|
||||
* Clients are encouraged to create a date-time formatter using DateFormat::getInstance(),
|
||||
* getDateInstance(), getDateInstance(), or getDateTimeInstance() rather than
|
||||
* explicitly constructing an instance of SimpleDateFormat. This way, the client
|
||||
* is guaranteed to get an appropriate formatting pattern for whatever locale the
|
||||
* program is running in. However, if the client needs something more unusual than
|
||||
* the default patterns in the locales, he can construct a SimpleDateFormat directly
|
||||
* and give it an appropriate pattern (or use one of the factory methods on DateFormat
|
||||
* and modify the pattern after the fact with toPattern() and applyPattern().
|
||||
* <P>
|
||||
* Date/Time format syntax:
|
||||
* <P>
|
||||
* The date/time format is specified by means of a string time pattern. In this
|
||||
* pattern, all ASCII letters are reserved as pattern letters, which are defined
|
||||
* as the following:
|
||||
* <pre>
|
||||
* . Symbol Meaning Presentation Example
|
||||
* . ------ ------- ------------ -------
|
||||
* . G era designator (Text) AD
|
||||
* . y year (Number) 1996
|
||||
* . M month in year (Text & Number) July & 07
|
||||
* . d day in month (Number) 10
|
||||
* . h hour in am/pm (1~12) (Number) 12
|
||||
* . H hour in day (0~23) (Number) 0
|
||||
* . m minute in hour (Number) 30
|
||||
* . s second in minute (Number) 55
|
||||
* . S millisecond (Number) 978
|
||||
* . E day in week (Text) Tuesday
|
||||
* . D day in year (Number) 189
|
||||
* . F day of week in month (Number) 2 (2nd Wed in July)
|
||||
* . w week in year (Number) 27
|
||||
* . W week in month (Number) 2
|
||||
* . a am/pm marker (Text) PM
|
||||
* . k hour in day (1~24) (Number) 24
|
||||
* . K hour in am/pm (0~11) (Number) 0
|
||||
* . z time zone (Text) Pacific Standard Time
|
||||
* . ' escape for text
|
||||
* . '' single quote '
|
||||
* </pre>
|
||||
* The count of pattern letters determine the format.
|
||||
* <P>
|
||||
* (Text): 4 or more, use full form, <4, use short or abbreviated form if it
|
||||
* exists. (e.g., "EEEE" produces "Monday", "EEE" produces "Mon")
|
||||
* <P>
|
||||
* (Number): the minimum number of digits. Shorter numbers are zero-padded to
|
||||
* this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is handled
|
||||
* specially; that is, if the count of 'y' is 2, the Year will be truncated to 2 digits.
|
||||
* (e.g., if "yyyy" produces "1997", "yy" produces "97".)
|
||||
* <P>
|
||||
* (Text & Number): 3 or over, use text, otherwise use number. (e.g., "M" produces "1",
|
||||
* "MM" produces "01", "MMM" produces "Jan", and "MMMM" produces "January".)
|
||||
* <P>
|
||||
* Any characters in the pattern that are not in the ranges of ['a'..'z'] and
|
||||
* ['A'..'Z'] will be treated as quoted text. For instance, characters
|
||||
* like ':', '.', ' ', '#' and '@' will appear in the resulting time text
|
||||
* even they are not embraced within single quotes.
|
||||
* <P>
|
||||
* A pattern containing any invalid pattern letter will result in a failing
|
||||
* ErrorCode result during formatting or parsing.
|
||||
* <P>
|
||||
* Examples using the US locale:
|
||||
* <pre>
|
||||
* . Format Pattern Result
|
||||
* . -------------- -------
|
||||
* . "yyyy.MM.dd G 'at' HH:mm:ss z" ->> 1996.07.10 AD at 15:08:56 PDT
|
||||
* . "EEE, MMM d, ''yy" ->> Wed, July 10, '96
|
||||
* . "h:mm a" ->> 12:08 PM
|
||||
* . "hh 'o''clock' a, zzzz" ->> 12 o'clock PM, Pacific Daylight Time
|
||||
* . "K:mm a, z" ->> 0:00 PM, PST
|
||||
* . "yyyyy.MMMMM.dd GGG hh:mm aaa" ->> 1996.July.10 AD 12:08 PM
|
||||
* </pre>
|
||||
* Code Sample:
|
||||
* <pre>
|
||||
* . SimpleTimeZone *pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000);
|
||||
* . pdt->setStartRule(DateFields.APRIL, 1, DateFields.SUNDAY, 2*60*60*1000);
|
||||
* . pdt->setEndRule(DateFields.OCTOBER, -1, DateFields.SUNDAY, 2*60*60*1000);
|
||||
*
|
||||
* . // Format the current time.
|
||||
* . SimpleDateFormat *formatter
|
||||
* . = new SimpleDateFormat ("yyyy.mm.dd G 'at' hh:mm:ss a zzz");
|
||||
* . Date *currentTime_1 = new Date();
|
||||
* . FieldPosition pos(0);
|
||||
* . String dateString;
|
||||
* . formatter.format(currentTime_1, dateString, pos);
|
||||
* .
|
||||
* . // Parse the previous string back into a Date.
|
||||
* . ParsePosition pos(0);
|
||||
* . formatter.parse(currentTime_2, dateString, pos);
|
||||
* </pre>
|
||||
* In the above example, the time value "currentTime_2" obtained from parsing
|
||||
* will be equal to currentTime_1. However, they may not be equal if the am/pm
|
||||
* marker 'a' is left out from the format pattern while the "hour in am/pm"
|
||||
* pattern symbol is used. This information loss can happen when formatting the
|
||||
* time in PM.
|
||||
* <P>
|
||||
* For time zones that have no names, SimpleDateFormat uses strings GMT+hours:minutes or
|
||||
* GMT-hours:minutes.
|
||||
* <P>
|
||||
* The calendar defines what is the first day of the week, the first week of the
|
||||
* year, whether hours are zero based or not (0 vs 12 or 24), and the timezone.
|
||||
* There is one common number format to handle all the numbers; the digit count
|
||||
* is handled programmatically according to the pattern.
|
||||
*/
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
class T_FORMAT_API SimpleDateFormat: public DateFormat {
|
||||
public:
|
||||
/**
|
||||
* Construct a SimpleDateFormat using the default pattern for the default
|
||||
* locale.
|
||||
* <P>
|
||||
* [Note:] Not all locales support SimpleDateFormat; for full generality,
|
||||
* use the factory methods in the DateFormat class.
|
||||
*/
|
||||
SimpleDateFormat(ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Construct a SimpleDateFormat using the given pattern and the default locale.
|
||||
* The locale is used to obtain the symbols used in formatting (e.g., the
|
||||
* names of the months), but not to provide the pattern.
|
||||
* <P>
|
||||
* [Note:] Not all locales support SimpleDateFormat; for full generality,
|
||||
* use the factory methods in the DateFormat class.
|
||||
*/
|
||||
SimpleDateFormat(const UnicodeString& pattern,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Construct a SimpleDateFormat using the given pattern and locale.
|
||||
* The locale is used to obtain the symbols used in formatting (e.g., the
|
||||
* names of the months), but not to provide the pattern.
|
||||
* <P>
|
||||
* [Note:] Not all locales support SimpleDateFormat; for full generality,
|
||||
* use the factory methods in the DateFormat class.
|
||||
*/
|
||||
SimpleDateFormat(const UnicodeString& pattern,
|
||||
const Locale& locale,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Construct a SimpleDateFormat using the given pattern and locale-specific
|
||||
* symbol data. The formatter takes ownership of the DateFormatSymbols object;
|
||||
* the caller is no longer responsible for deleting it.
|
||||
*/
|
||||
SimpleDateFormat(const UnicodeString& pattern,
|
||||
DateFormatSymbols* formatDataToAdopt,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Construct a SimpleDateFormat using the given pattern and locale-specific
|
||||
* symbol data. The DateFormatSymbols object is NOT adopted; the caller
|
||||
* remains responsible for deleting it.
|
||||
*/
|
||||
SimpleDateFormat(const UnicodeString& pattern,
|
||||
const DateFormatSymbols& formatData,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
SimpleDateFormat(const SimpleDateFormat&);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*/
|
||||
SimpleDateFormat& operator=(const SimpleDateFormat&);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~SimpleDateFormat();
|
||||
|
||||
/**
|
||||
* Clone this Format object polymorphically. The caller owns the result and
|
||||
* should delete it when done.
|
||||
*/
|
||||
virtual Format* clone() const;
|
||||
|
||||
/**
|
||||
* Return true if the given Format objects are semantically equal. Objects
|
||||
* of different subclasses are considered unequal.
|
||||
*/
|
||||
virtual t_bool operator==(const Format& other) const;
|
||||
|
||||
/**
|
||||
* Format a date or time, which is the standard millis since 24:00 GMT, Jan
|
||||
* 1, 1970. Overrides DateFormat pure virtual method.
|
||||
* <P>
|
||||
* Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
|
||||
* 1996.07.10 AD at 15:08:56 PDT
|
||||
*
|
||||
* @param date The date-time value to be formatted into a date-time string.
|
||||
* @param toAppendTo The result of the formatting operation is appended to this
|
||||
* string.
|
||||
* @param pos The formatting position. On input: an alignment field,
|
||||
* if desired. On output: the offsets of the alignment field.
|
||||
* @return A reference to 'toAppendTo'.
|
||||
*/
|
||||
virtual UnicodeString& format( Date date,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos) const;
|
||||
|
||||
/**
|
||||
* Format a date or time, which is the standard millis since 24:00 GMT, Jan
|
||||
* 1, 1970. Overrides DateFormat pure virtual method.
|
||||
* <P>
|
||||
* Example: using the US locale: "yyyy.MM.dd e 'at' HH:mm:ss zzz" ->>
|
||||
* 1996.07.10 AD at 15:08:56 PDT
|
||||
*
|
||||
* @param obj A Formattable containing the date-time value to be formatted
|
||||
* into a date-time string. If the type of the Formattable
|
||||
* is a numeric type, it is treated as if it were an
|
||||
* instance of Date.
|
||||
* @param toAppendTo The result of the formatting operation is appended to this
|
||||
* string.
|
||||
* @param pos The formatting position. On input: an alignment field,
|
||||
* if desired. On output: the offsets of the alignment field.
|
||||
* @return A reference to 'toAppendTo'.
|
||||
*/
|
||||
virtual UnicodeString& format( const Formattable& obj,
|
||||
UnicodeString& toAppendTo,
|
||||
FieldPosition& pos,
|
||||
ErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Parse a date/time string starting at the given parse position. For
|
||||
* example, a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date
|
||||
* that is equivalent to Date(837039928046).
|
||||
* <P>
|
||||
* By default, parsing is lenient: If the input is not in the form used by
|
||||
* this object's format method but can still be parsed as a date, then the
|
||||
* parse succeeds. Clients may insist on strict adherence to the format by
|
||||
* calling setLenient(false).
|
||||
*
|
||||
* @see DateFormat::setLenient(boolean)
|
||||
*
|
||||
* @param text The date/time string to be parsed
|
||||
* @param pos On input, the position at which to start parsing; on
|
||||
* output, the position at which parsing terminated, or the
|
||||
* start position if the parse failed.
|
||||
* @return A valid Date if the input could be parsed.
|
||||
*/
|
||||
virtual Date parse( const UnicodeString& text,
|
||||
ParsePosition& pos) const;
|
||||
|
||||
|
||||
/**
|
||||
* Parse a date/time string. For example, a time text "07/10/96 4:5 PM, PDT"
|
||||
* will be parsed into a Date that is equivalent to Date(837039928046).
|
||||
* Parsing begins at the beginning of the string and proceeds as far as
|
||||
* possible. Assuming no parse errors were encountered, this function
|
||||
* doesn't return any information about how much of the string was consumed
|
||||
* by the parsing. If you need that information, use the version of
|
||||
* parse() that takes a ParsePosition.
|
||||
*
|
||||
* @param text The date/time string to be parsed
|
||||
* @param status Filled in with ZERO_ERROR if the parse was successful, and with
|
||||
* an error value if there was a parse error.
|
||||
* @return A valid Date if the input could be parsed.
|
||||
*/
|
||||
virtual Date parse( const UnicodeString& text,
|
||||
ErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Set the start Date used to interpret two-digit year strings.
|
||||
* When dates are parsed having 2-digit year strings, they are placed within
|
||||
* a assumed range of 100 years starting on the two digit start date. For
|
||||
* example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
|
||||
* some other year. SimpleDateFormat chooses a year so that the resultant
|
||||
* date is on or after the two digit start date and within 100 years of the
|
||||
* two digit start date.
|
||||
* <P>
|
||||
* By default, the two digit start date is set to 80 years before the current
|
||||
* time at which a SimpleDateFormat object is created.
|
||||
*/
|
||||
virtual void setTwoDigitStartDate(Date d, ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Get the start Date used to interpret two-digit year strings.
|
||||
* When dates are parsed having 2-digit year strings, they are placed within
|
||||
* a assumed range of 100 years starting on the two digit start date. For
|
||||
* example, the string "24-Jan-17" may be in the year 1817, 1917, 2017, or
|
||||
* some other year. SimpleDateFormat chooses a year so that the resultant
|
||||
* date is on or after the two digit start date and within 100 years of the
|
||||
* two digit start date.
|
||||
* <P>
|
||||
* By default, the two digit start date is set to 80 years before the current
|
||||
* time at which a SimpleDateFormat object is created.
|
||||
*/
|
||||
Date getTwoDigitStartDate(ErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Return a pattern string describing this date format.
|
||||
*/
|
||||
virtual UnicodeString& toPattern(UnicodeString& result) const;
|
||||
|
||||
/**
|
||||
* Return a localized pattern string describing this date format.
|
||||
* In most cases, this will return the same thing as toPattern(),
|
||||
* but a locale can specify characters to use in pattern descriptions
|
||||
* in place of the ones described in this class's class documentation.
|
||||
* (Presumably, letters that would be more mnemonic in that locale's
|
||||
* language.) This function would produce a pattern using those
|
||||
* letters.
|
||||
*
|
||||
* @param result Receives the localized pattern.
|
||||
* @param status Output param set to success/failure code on
|
||||
* exit. If the pattern is invalid, this will be
|
||||
* set to a failure result.
|
||||
*/
|
||||
virtual UnicodeString& toLocalizedPattern(UnicodeString& result,
|
||||
ErrorCode& status) const;
|
||||
|
||||
/**
|
||||
* Apply the given unlocalized pattern string to this date format.
|
||||
* (i.e., after this call, this formatter will format dates according to
|
||||
* the new pattern)
|
||||
*
|
||||
* @param pattern The pattern to be applied.
|
||||
*/
|
||||
virtual void applyPattern(const UnicodeString& pattern);
|
||||
|
||||
/**
|
||||
* Apply the given localized pattern string to this date format.
|
||||
* (see toLocalizedPattern() for more information on localized patterns.)
|
||||
*
|
||||
* @param pattern The localized pattern to be applied.
|
||||
* @param status Output param set to success/failure code on
|
||||
* exit. If the pattern is invalid, this will be
|
||||
* set to a failure result.
|
||||
*/
|
||||
virtual void applyLocalizedPattern(const UnicodeString& pattern,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Gets the date/time formatting symbols (this is an object carrying
|
||||
* the various strings and other symbols used in formatting: e.g., month
|
||||
* names and abbreviations, time zone names, AM/PM strings, etc.)
|
||||
* @return a copy of the date-time formatting data associated
|
||||
* with this date-time formatter.
|
||||
*/
|
||||
virtual const DateFormatSymbols* getDateFormatSymbols() const;
|
||||
|
||||
/**
|
||||
* Set the date/time formatting symbols. The caller no longer owns the
|
||||
* DateFormatSymbols object and should not delete it after making this call.
|
||||
* @param newFormatData the given date-time formatting data.
|
||||
*/
|
||||
virtual void adoptDateFormatSymbols(DateFormatSymbols* newFormatSymbols);
|
||||
|
||||
/**
|
||||
* Set the date/time formatting data.
|
||||
* @param newFormatData the given date-time formatting data.
|
||||
*/
|
||||
virtual void setDateFormatSymbols(const DateFormatSymbols& newFormatSymbols);
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Resource bundle file suffix and tag names used by this class.
|
||||
*/
|
||||
static const UnicodeString kErasTag; // resource bundle tag for era names
|
||||
static const UnicodeString kMonthNamesTag; // resource bundle tag for month names
|
||||
static const UnicodeString kMonthAbbreviationsTag; // resource bundle tag for month abbreviations
|
||||
static const UnicodeString kDayNamesTag; // resource bundle tag for day names
|
||||
static const UnicodeString kDayAbbreviationsTag; // resource bundle tag for day abbreviations
|
||||
static const UnicodeString kAmPmMarkersTag; // resource bundle tag for AM/PM strings
|
||||
static const UnicodeString kDateTimePatternsTag; // resource bundle tag for default date and time patterns
|
||||
|
||||
static const char* kTimeZoneDataSuffix; // filename suffix for time-zone data file
|
||||
static const UnicodeString kZoneStringsTag; // resource bundle tag for time zone names
|
||||
static const UnicodeString kLocalPatternCharsTag; // resource bundle tag for localized pattern characters
|
||||
|
||||
static const UnicodeString kDefaultPattern; // date/time pattern of last resort
|
||||
|
||||
public:
|
||||
/**
|
||||
* Return the class ID for this class. This is useful only for comparing to
|
||||
* a return value from getDynamicClassID(). For example:
|
||||
* <pre>
|
||||
* . Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* . if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* . erived::getStaticClassID()) ...
|
||||
* </pre>
|
||||
* @return The class ID for all objects of this class.
|
||||
*/
|
||||
static ClassID getStaticClassID() { return (ClassID)&fgClassID; }
|
||||
|
||||
/**
|
||||
* Returns a unique class ID POLYMORPHICALLY. Pure virtual override. This
|
||||
* method is to implement a simple version of RTTI, since not all C++
|
||||
* compilers support genuine RTTI. Polymorphic operator==() and clone()
|
||||
* methods call this method.
|
||||
*
|
||||
* @return The class ID for this object. All objects of a
|
||||
* given class have the same class ID. Objects of
|
||||
* other classes have different class IDs.
|
||||
*/
|
||||
virtual ClassID getDynamicClassID() const { return getStaticClassID(); }
|
||||
|
||||
private:
|
||||
static char fgClassID;
|
||||
|
||||
friend class DateFormat;
|
||||
|
||||
/**
|
||||
* Gets the index for the given time zone ID to obtain the timezone strings
|
||||
* for formatting. The time zone ID is just for programmatic lookup. NOT
|
||||
* LOCALIZED!!!
|
||||
*
|
||||
* @param DateFormatSymbols a DateFormatSymbols object contianing the time zone names
|
||||
* @param ID the given time zone ID.
|
||||
* @return the index of the given time zone ID. Returns -1 if
|
||||
* the given time zone ID can't be located in the
|
||||
* DateFormatSymbols object.
|
||||
* @see SimpleTimeZone
|
||||
*/
|
||||
int getZoneIndex(const DateFormatSymbols&, const UnicodeString& ID) const;
|
||||
|
||||
/**
|
||||
* Used by the DateFormat factory methods to construct a SimpleDateFormat.
|
||||
*/
|
||||
SimpleDateFormat(EStyle timeStyle, EStyle dateStyle, const Locale& locale, ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Construct a SimpleDateFormat for the given locale. If no resource data
|
||||
* is available, create an object of last resort, using hard-coded strings.
|
||||
* This is an internal method, called by DateFormat. It should never fail.
|
||||
*/
|
||||
SimpleDateFormat(const Locale& locale, ErrorCode& status); // Use default pattern
|
||||
|
||||
/**
|
||||
* Called by format() to format a single field.
|
||||
*
|
||||
* @param result Filled in with the result.
|
||||
* @param ch The format character we encountered in the pattern.
|
||||
* @param count Number of characters in the current pattern symbol (e.g.,
|
||||
* "yyyy" in the pattern would result in a call to this function
|
||||
* with ch equal to 'y' and count equal to 4)
|
||||
* @param beginOffset Tells where the text returned by this function will go in
|
||||
* the finished string. Used when this function needs to fill
|
||||
* in a FieldPosition
|
||||
* @param pos The FieldPosition being filled in by the format() call. If
|
||||
* this function is formatting the field specfied by pos, it
|
||||
* will fill in pos will the beginning and ending offsets of the
|
||||
* field.
|
||||
* @param status Receives a status code, which will be ZERO_ERROR if the operation
|
||||
* succeeds.
|
||||
* @return A reference to "result".
|
||||
*/
|
||||
UnicodeString& subFormat( UnicodeString& result,
|
||||
UniChar ch,
|
||||
int count,
|
||||
int beginOffset,
|
||||
FieldPosition& pos,
|
||||
ErrorCode& status) const; // in case of illegal argument
|
||||
|
||||
/**
|
||||
* Used by subFormat() to format a numeric value. Fills in "result" with a string
|
||||
* representation of "value" having a number of digits between "minDigits" and
|
||||
* "maxDigits". Uses the DateFormat's NumberFormat.
|
||||
* @param result Filled in with the formatted number.
|
||||
* @param value Value to format.
|
||||
* @param minDigits Minimum number of digits the result should have
|
||||
* @param maxDigits Maximum number of digits the result should have
|
||||
* @return A reference to "result".
|
||||
*/
|
||||
UnicodeString& zeroPaddingNumber(UnicodeString& result,
|
||||
long value,
|
||||
int minDigits,
|
||||
int maxDigits) const;
|
||||
|
||||
/**
|
||||
* Called by several of the constructors to load pattern data and formatting symbols
|
||||
* out of a resource bundle and initialize the locale based on it.
|
||||
* @param timeStyle The time style, as passed to DateFormat::createDateInstance().
|
||||
* @param dateStyle The date style, as passed to DateFormat::createTimeInstance().
|
||||
* @param locale The locale to load the patterns from.
|
||||
* @param status Filled in with an error code if loading the data from the
|
||||
* resources fails.
|
||||
*/
|
||||
void construct(EStyle timeStyle, EStyle dateStyle, const Locale& locale, ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Called by construct() and the various constructors to set up the SimpleDateFormat's
|
||||
* Calendar and NumberFormat objects.
|
||||
* @param locale The locale for which we want a Calendar and a NumberFormat.
|
||||
* @param statuc Filled in with an error code if creating either subobject fails.
|
||||
*/
|
||||
void initialize(const Locale& locale, ErrorCode& status);
|
||||
|
||||
/**
|
||||
* Private code-size reduction function used by subParse.
|
||||
* @param text the time text being parsed.
|
||||
* @param start where to start parsing.
|
||||
* @param field the date field being parsed.
|
||||
* @param data the string array to parsed.
|
||||
* @return the new start position if matching succeeded; a negative number
|
||||
* indicating matching failure, otherwise.
|
||||
*/
|
||||
int matchString(const UnicodeString& text, TextOffset start, Calendar::EDateFields field,
|
||||
const UnicodeString* stringArray, t_int32 stringArrayCount) const;
|
||||
|
||||
/**
|
||||
* Private member function that converts the parsed date strings into
|
||||
* timeFields. Returns -start (for ParsePosition) if failed.
|
||||
* @param text the time text to be parsed.
|
||||
* @param start where to start parsing.
|
||||
* @param ch the pattern character for the date field text to be parsed.
|
||||
* @param count the count of a pattern character.
|
||||
* @param obeyCount if true then the count is strictly obeyed.
|
||||
* @return the new start position if matching succeeded; a negative number
|
||||
* indicating matching failure, otherwise.
|
||||
*/
|
||||
int subParse(const UnicodeString& text, ParsePosition& start, UniChar ch, int count,
|
||||
t_bool obeyCount, t_bool& ambiguousYear) const;
|
||||
|
||||
/**
|
||||
* Parse the given text, at the given position, as a numeric value, using
|
||||
* this object's NumberFormat. Return the corresponding long value in the
|
||||
* fill-in parameter 'value'. If the parse fails, this method leaves pos
|
||||
* unchanged and returns FALSE; otherwise it advances pos and
|
||||
* returns TRUE.
|
||||
*/
|
||||
t_bool subParseLong(const UnicodeString& text, ParsePosition& pos, long& value) const;
|
||||
|
||||
/**
|
||||
* Translate a pattern, mapping each character in the from string to the
|
||||
* corresponding character in the to string. Return an error if the original
|
||||
* pattern contains an unmapped character, or if a quote is unmatched.
|
||||
* Quoted (single quotes only) material is not translated.
|
||||
*/
|
||||
static void translatePattern(const UnicodeString& originalPattern,
|
||||
UnicodeString& translatedPattern,
|
||||
const UnicodeString& from,
|
||||
const UnicodeString& to,
|
||||
ErrorCode& status);
|
||||
/**
|
||||
* Given a zone ID, try to locate it in our time zone array. Return the
|
||||
* index (row index) of the found time zone, or -1 if we can't find it.
|
||||
*/
|
||||
int getZoneIndex(const UnicodeString& ID) const;
|
||||
|
||||
/**
|
||||
* Sets the starting date of the 100-year window that dates with 2-digit years
|
||||
* are considered to fall within.
|
||||
*/
|
||||
void parseAmbiguousDatesAsAfter(Date startDate);
|
||||
|
||||
/**
|
||||
* Returns the beginning date of the 100-year window that dates with 2-digit years
|
||||
* are considered to fall within.
|
||||
*/
|
||||
Date internalGetDefaultCenturyStart() const;
|
||||
|
||||
/**
|
||||
* Returns the first year of the 100-year window that dates with 2-digit years
|
||||
* are considered to fall within.
|
||||
*/
|
||||
int internalGetDefaultCenturyStartYear() const;
|
||||
|
||||
/**
|
||||
* Initializes the 100-year window that dates with 2-digit years are considered
|
||||
* to fall within so that its start date is 80 years before the current time.
|
||||
*/
|
||||
static void initializeSystemDefaultCentury();
|
||||
|
||||
/**
|
||||
* Last-resort string to use for "GMT" when constructing time zone strings.
|
||||
*/
|
||||
static const UnicodeString GMT;
|
||||
|
||||
/**
|
||||
* Used to map pattern characters to Calendar field identifiers.
|
||||
*/
|
||||
static const Calendar::EDateFields PATTERN_INDEX_TO_FIELD[];
|
||||
|
||||
/**
|
||||
* The formatting pattern for this formatter.
|
||||
*/
|
||||
UnicodeString fPattern;
|
||||
|
||||
/**
|
||||
* A pointer to an object containing the strings to use in formatting (e.g.,
|
||||
* month and day names, AM and PM strings, time zone names, etc.)
|
||||
*/
|
||||
DateFormatSymbols* fSymbols; // Owned
|
||||
|
||||
/**
|
||||
* If dates have ambiguous years, we map them into the century starting
|
||||
* at defaultCenturyStart, which may be any date. If defaultCenturyStart is
|
||||
* set to SYSTEM_DEFAULT_CENTURY, which it is by default, then the system
|
||||
* values are used. The instance values defaultCenturyStart and
|
||||
* defaultCenturyStartYear are only used if explicitly set by the user
|
||||
* through the API method parseAmbiguousDatesAsAfter().
|
||||
*/
|
||||
Date defaultCenturyStart;
|
||||
|
||||
/**
|
||||
* See documentation for defaultCenturyStart.
|
||||
*/
|
||||
/*transient*/ int defaultCenturyStartYear;
|
||||
|
||||
/**
|
||||
* The system maintains a static default century start date. This is initialized
|
||||
* the first time it is used. Before then, it is set to SYSTEM_DEFAULT_CENTURY to
|
||||
* indicate an uninitialized state. Once the system default century date and year
|
||||
* are set, they do not change.
|
||||
*/
|
||||
static Date systemDefaultCenturyStart;
|
||||
|
||||
/**
|
||||
* See documentation for systemDefaultCenturyStart.
|
||||
*/
|
||||
static int systemDefaultCenturyStartYear;
|
||||
|
||||
public:
|
||||
/**
|
||||
* If a start date is set to this value, that indicates that the system default
|
||||
* start is in effect for this instance.
|
||||
*/
|
||||
static const Date SYSTEM_DEFAULT_CENTURY;
|
||||
};
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
inline Date
|
||||
SimpleDateFormat::getTwoDigitStartDate(ErrorCode& status) const
|
||||
{
|
||||
return defaultCenturyStart;
|
||||
}
|
||||
|
||||
#endif // _SMPDTFMT
|
||||
//eof
|
|
@ -0,0 +1,787 @@
|
|||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1996 *
|
||||
* (C) Copyright International Business Machines Corporation, 1996 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
//===============================================================================
|
||||
//
|
||||
// File tblcoll.h
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by: Helena Shih
|
||||
//
|
||||
// Modification History:
|
||||
//
|
||||
// Date Name Description
|
||||
// 2/5/97 aliu Added streamIn and streamOut methods. Added
|
||||
// constructor which reads RuleBasedCollator object from
|
||||
// a binary file. Added writeToFile method which streams
|
||||
// RuleBasedCollator out to a binary file. The streamIn
|
||||
// and streamOut methods use istream and ostream objects
|
||||
// in binary mode.
|
||||
// 2/12/97 aliu Modified to use TableCollationData sub-object to
|
||||
// hold invariant data.
|
||||
// 2/13/97 aliu Moved several methods into this class from Collation.
|
||||
// Added a private RuleBasedCollator(Locale&) constructor,
|
||||
// to be used by Collator::createDefault(). General
|
||||
// clean up.
|
||||
// 2/20/97 helena Added clone, operator==, operator!=, operator=, and copy
|
||||
// constructor and getDynamicClassID.
|
||||
// 3/5/97 aliu Modified constructFromFile() to add parameter
|
||||
// specifying whether or not binary loading is to be
|
||||
// attempted. This is required for dynamic rule loading.
|
||||
// 05/07/97 helena Added memory allocation error detection.
|
||||
// 6/17/97 helena Added IDENTICAL strength for compare, changed getRules to
|
||||
// use MergeCollation::getPattern.
|
||||
// 6/20/97 helena Java class name change.
|
||||
// 8/18/97 helena Added internal API documentation.
|
||||
// 09/03/97 helena Added createCollationKeyValues().
|
||||
// 02/10/98 damiba Added compare with "length" parameter
|
||||
//===============================================================================
|
||||
|
||||
#ifndef _TBLCOLL
|
||||
#define _TBLCOLL
|
||||
|
||||
#ifndef _PTYPES
|
||||
#include "ptypes.h"
|
||||
#endif
|
||||
|
||||
#ifndef _COLL
|
||||
#include "coll.h"
|
||||
#endif
|
||||
|
||||
#ifndef _UNISTRING
|
||||
#include "unistring.h"
|
||||
#endif
|
||||
|
||||
#ifndef _SORTKEY
|
||||
#include "sortkey.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
class CompactIntArray;
|
||||
class VectorOfPToContractElement;
|
||||
class VectorOfInt;
|
||||
class VectorOfPToContractTable;
|
||||
class VectorOfPToExpandTable;
|
||||
class MergeCollation;
|
||||
class CollationElementIterator;
|
||||
|
||||
/**
|
||||
* The RuleBasedCollator class provides the simple implementation of Collator,
|
||||
* using data-driven tables. The user can create a customized table-based
|
||||
* collation.
|
||||
* <P>
|
||||
* RuleBasedCollator maps characters to collation keys.
|
||||
* <p>
|
||||
* Table Collation has the following restrictions for efficiency (other
|
||||
* subclasses may be used for more complex languages) :
|
||||
* <p>1. If the French secondary ordering is specified in a collation object,
|
||||
* it is applied to the whole object.
|
||||
* <p>2. All non-mentioned Unicode characters are at the end of the
|
||||
* collation order.
|
||||
* <p>3. Private use characters are treated as identical. The private
|
||||
* use area in Unicode is 0xE800-0xF8FF.
|
||||
* <p>The collation table is composed of a list of collation rules, where each
|
||||
* rule is of three forms:
|
||||
* <pre>
|
||||
* . < modifier >
|
||||
* . < relation > < text-argument >
|
||||
* . < reset > < text-argument >
|
||||
* </pre>
|
||||
* The following demonstrates how to create your own collation rules:
|
||||
* <UL Type=round>
|
||||
* <LI><strong>Text Argument</strong>: A text argument is any sequence of
|
||||
* characters, excluding special characters (that is, whitespace
|
||||
* characters and the characters used in modifier, relation and reset).
|
||||
* If those characters are desired, you can put them in single quotes
|
||||
* (e.g. ampersand => '&').<P>
|
||||
* <LI><strong>Modifier</strong>: There is a single modifier,
|
||||
* which is used to specify that all secondary differences are
|
||||
* sorted backwards.
|
||||
* <p>'@' : Indicates that secondary differences, such as accents, are
|
||||
* sorted backwards, as in French.<P>
|
||||
* <LI><strong>Relation</strong>: The relations are the following:
|
||||
* <UL Type=square>
|
||||
* <LI>'<' : Greater, as a letter difference (primary)
|
||||
* <LI>';' : Greater, as an accent difference (secondary)
|
||||
* <LI>',' : Greater, as a case difference (tertiary)
|
||||
* <LI>'=' : Equal
|
||||
* </UL><P>
|
||||
* <LI><strong>Reset</strong>: There is a single reset,
|
||||
* which is used primarily for contractions and expansions, but which
|
||||
* can also be used to add a modification at the end of a set of rules.
|
||||
* <p>'&' : Indicates that the next rule follows the position to where
|
||||
* the reset text-argument would be sorted.
|
||||
*
|
||||
* <P>Note : The ASCII punctuation characters 0x0020..0x002F, 0x003A..0x0040,
|
||||
* 0x005B..0x0060, 0x007B..0x007E are reserved for use in the syntax for
|
||||
* building patterns. That is these all have to be quoted if they occur
|
||||
* as literals.
|
||||
* <p>
|
||||
* This sounds more complicated than it is in practice. For example, the
|
||||
* following are equivalent ways of expressing the same thing:
|
||||
* <pre>
|
||||
* . a < b < c
|
||||
* . a < b & b < c
|
||||
* . a < c & a < b
|
||||
* </pre>
|
||||
* Notice that the order is important, as the subsequent item goes immediately
|
||||
* after the text-argument. The following are not equivalent:
|
||||
* <pre>
|
||||
* . a < b & a < c
|
||||
* . a < c & a < b
|
||||
* </pre>
|
||||
* Either the text-argument must already be present in the sequence, or some
|
||||
* initial substring of the text-argument must be present. (e.g. "a < b & ae <
|
||||
* e" is valid since "a" is present in the sequence before "ae" is reset). In
|
||||
* this latter case, "ae" is not entered and treated as a single character;
|
||||
* instead, "e" is sorted as if it were expanded to two characters: "a"
|
||||
* followed by an "e". This difference appears in natural languages: in
|
||||
* traditional Spanish "ch" is treated as though it contracts to a single
|
||||
* character (expressed as "c < ch < d"), while in traditional German "ä"
|
||||
* (a-umlaut) is treated as though it expands to two characters (expressed as
|
||||
* "a & ae ; ä < b").
|
||||
* <p><strong>Ignorable Characters</strong>
|
||||
* <p>For ignorable characters, the first rule must start with a relation (the
|
||||
* examples we have used above are really fragments; "a < b" really should be
|
||||
* "< a < b"). If, however, the first relation is not "<", then all the
|
||||
* text-arguments up to the first "<" are ignorable. For example, ", - < a < b"
|
||||
* makes "-" an ignorable character, as we saw earlier in the word
|
||||
* "black-birds". In the samples for different languages, you see that most
|
||||
* accents are ignorable.
|
||||
* <p><strong>Normalization and Accents</strong>
|
||||
* <p>The Collator object automatically normalizes text internally to separate
|
||||
* accents from base characters where possible. This is done both when
|
||||
* processing the rules, and when comparing two strings. Collator also uses
|
||||
* the Unicode canonical mapping to ensure that combining sequences are sorted
|
||||
* properly (for more information, see <A HREF="http://www.aw.com/devpress">
|
||||
* The Unicode Standard, Version 2.0</A>.)</P>
|
||||
* <p><strong>Errors</strong>
|
||||
* <p>The following are errors:
|
||||
* <UL Type=round>
|
||||
* <LI>A text-argument contains unquoted punctuation symbols
|
||||
* (e.g. "a < b-c < d").
|
||||
* <LI>A relation or reset character not followed by a text-argument
|
||||
* (e.g. "a < , b").
|
||||
* <LI>A reset where the text-argument (or an initial substring of the
|
||||
* text-argument) is not already in the sequence.
|
||||
* (e.g. "a < b & e < f")
|
||||
* </UL>
|
||||
* If you produce one of these errors, a FormatException will be thrown by
|
||||
* RuleBasedCollator.
|
||||
* <pre>
|
||||
* . Examples:
|
||||
* . Simple: "< a < b < c < d"
|
||||
* . Norwegian: "< a,A< b,B< c,C< d,D< e,E< f,F< g,G< h,H< i,I< j,J
|
||||
* . < k,K< l,L< m,M< n,N< o,O< p,P< q,Q< r,R< s,S< t,T
|
||||
* . < u,U< v,V< w,W< x,X< y,Y< z,Z
|
||||
* . < å=a°,Å=A°
|
||||
* . ;aa,AA< æ,Æ< ø,Ø"
|
||||
* </pre>
|
||||
* <p>To create a table-based collation object, simply supply the collation
|
||||
* rules to the RuleBasedCollator contructor. For example:
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . RuleBasedCollator *mySimple = new RuleBasedCollator(Simple, status);
|
||||
* </pre>
|
||||
* <p>Another example:
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . RuleBasedCollator *myNorwegian = new RuleBasedCollator(Norwegian, status);
|
||||
* </pre>
|
||||
* To add rules on top of an existing table, simply supply the orginal rules
|
||||
* and modifications to RuleBasedCollator constructor. For example,
|
||||
* <pre>
|
||||
* . Traditional Spanish (fragment): ... & C < ch , cH , Ch , CH ...
|
||||
* . German (fragment) : ...< y , Y < z , Z
|
||||
* . & AE, Ä & AE, ä
|
||||
* . & OE , Ö & OE, ö
|
||||
* . & UE , Ü & UE, ü
|
||||
* . Symbols (fragment): ...< y, Y < z , Z
|
||||
* . & Question-mark ; '?'
|
||||
* . & Ampersand ; '&'
|
||||
* . & Dollar-sign ; '$'
|
||||
* <p>To create a collation object for traditional Spanish, the user can take
|
||||
* the English collation rules and add the additional rules to the table.
|
||||
* For example:
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . UnicodeString rules(DEFAULTRULES);
|
||||
* . rules += "& C < ch, cH, Ch, CH";
|
||||
* . RuleBasedCollator *mySpanish = new RuleBasedCollator(rules, status);
|
||||
* </pre>
|
||||
* <p>In order to sort symbols in the similiar order of sorting their
|
||||
* alphabetic equivalents, you can do the following,
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . UnicodeString rules(DEFAULTRULES);
|
||||
* . rules += "& Question-mark ; '?' & Ampersand ; '&' & Dollar-sign ; '$' ";
|
||||
* . RuleBasedCollator *myTable = new RuleBasedCollator(rules, status);
|
||||
* </pre>
|
||||
* <p>Another way of creating the table-based collation object, mySimple,
|
||||
* is:
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . RuleBasedCollator *mySimple = new
|
||||
* . RuleBasedCollator(" < a < b & b < c & c < d", status);
|
||||
* </pre>
|
||||
* Or,
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . RuleBasedCollator *mySimple = new
|
||||
* . RuleBasedCollator(" < a < b < d & b < c", status);
|
||||
* </pre>
|
||||
* Because " < a < b < c < d" is the same as "a < b < d & b < c" or
|
||||
* "< a < b & b < c & c < d".
|
||||
*
|
||||
* <p>To combine collations from two locales,
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . // Create an en_US collation object
|
||||
* . RuleBasedCollator *en_USCollation = (RuleBasedCollator*)
|
||||
* . Collator::createInstance(Locale("en", "US", ""), status);
|
||||
* . if (FAILURE(status)) return;
|
||||
* . // Create a da_DK collation object
|
||||
* . RuleBasedCollator *da_DKCollation = (RuleBasedCollator*)
|
||||
* . Collator::getDefault(Locale("da", "DK", ""), status);
|
||||
* . if (FAILURE(status)) { delete en_USCollation; return; }
|
||||
* . // Combine the two
|
||||
* . // First, get the collation rules from en_USCollation
|
||||
* . const UnicodeString& en_USRules = en_USCollation->getRules();
|
||||
* . // Second, get the collation rules from da_DKCollation
|
||||
* . const UnicodeString& da_DKRules = da_DKCollation->getRules();
|
||||
* . UnicodeString newRules += en_USRules;
|
||||
* . newRules += da_DKRules;
|
||||
* . RuleBasedCollator *newCollation = new RuleBasedCollator(newRules, status);
|
||||
* . if (FAILURE(status)) { delete en_USCollation; delete da_DKCollation; return; }
|
||||
* . // newCollation has the combined rules
|
||||
* .
|
||||
* </pre>
|
||||
* <p>Another more interesting example would be to make changes on an existing
|
||||
* table to create a new collation object. For example, add
|
||||
* "& C < ch, cH, Ch, CH" to the en_USCollation object to create your own
|
||||
* English collation object,
|
||||
* <pre>
|
||||
* . // Create a new collation object with additional rules
|
||||
* . UnicodeString addRules(en_USRules);
|
||||
* . addRules += "& C < ch, cH, Ch, CH";
|
||||
* .
|
||||
* . RuleBasedCollator *myCollation = new RuleBasedCollator(addRules, status);
|
||||
* . // myCollation contains the new rules
|
||||
* </pre>
|
||||
*
|
||||
* <p>The following example demonstrates how to change the order of
|
||||
* non-spacing accents,
|
||||
* <pre>
|
||||
* . // old rule
|
||||
* . UniChar contents[] = {
|
||||
* . '=', 0x0301, ';', 0x0300, ';', 0x0302,
|
||||
* . ';', 0x0308, ';', 0x0327; ',', 0x0303, // main accents
|
||||
* . ';', 0x0304, ';', 0x0305, ';', 0x0306, // main accents
|
||||
* . ';', 0x0307, ';', 0x0309, ';', 0x030A, // main accents
|
||||
* . ';', 0x030B, ';', 0x030C, ';', 0x030D, // main accents
|
||||
* . ';', 0x030E, ';', 0x030F, ';', 0x0310, // main accents
|
||||
* . ';', 0x0311, ';', 0x0312, // main accents
|
||||
* . '<', 'a', ',', 'A', ';', 'a', 'e', ',', 'A', 'E',
|
||||
* . ';', 0x00e6, ',', 0x00c6, '<', 'b', ',', 'B',
|
||||
* . '<', 'c', ',', 'C', '<', 'e', ',', 'E', '&',
|
||||
* . 'C', '<', 'd', ',', 'D' };
|
||||
* . UnicodeString oldRules(contents);
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . // change the order of accent characters
|
||||
* . UniChar addOn[] = { '&', ',', 0x0300, ';', 0x0308, ';', 0x0302 };
|
||||
* . oldRules += addOn;
|
||||
* . RuleBasedCollator *myCollation = new RuleBasedCollator(oldRules, status);
|
||||
* </pre>
|
||||
*
|
||||
* <p> The last example shows how to put new primary ordering in before the
|
||||
* default setting. For example, in Japanese collation, you can either sort
|
||||
* English characters before or after Japanese characters,
|
||||
* <pre>
|
||||
* . ErrorCode status = ZERO_ERROR;
|
||||
* . // get en_US collation rules
|
||||
* . Collator *en_USCollation = Collator::createInstance(Locale::US, status);
|
||||
* . // Always check the error code after each call.
|
||||
* . if (FAILURE(status)) return;
|
||||
* . // add a few Japanese character to sort before English characters
|
||||
* . // suppose the last character before the first base letter 'a' in
|
||||
* . // the English collation rule is 0x2212
|
||||
* . UniChar jaString[] = { '&', 0x2212, '<', 0x3041, ',', 0x3042, '<', 0x3043, ',', 0x3044 };
|
||||
* . UnicodeString rules;
|
||||
* . rules += en_USCollation->getRules();
|
||||
* . rules += jaString;
|
||||
* . RuleBasedCollator *myJapaneseCollation = new RuleBasedCollator(rules, status);
|
||||
* .
|
||||
* </pre>
|
||||
* <p><strong>NOTE</strong>: Typically, a collation object is created with
|
||||
* Collator::createInstance().
|
||||
* @see Collator
|
||||
* @version 1.27 4/8/97
|
||||
* @author Helena Shih
|
||||
*/
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
class T_COLLATE_API RuleBasedCollator : public Collator {
|
||||
public :
|
||||
|
||||
// constructor/destructor
|
||||
/**
|
||||
* RuleBasedCollator constructor. This takes the table rules and builds
|
||||
* a collation table out of them. Please see RuleBasedCollator class
|
||||
* description for more details on the collation rule syntax.
|
||||
* @see Locale
|
||||
* @param rules the collation rules to build the collation table from.
|
||||
* @exception FormatException A format exception
|
||||
* will be thrown if the build process of the rules fails. For
|
||||
* example, build rule "a < b c < d" will cause the constructor to
|
||||
* throw the FormatException.
|
||||
*/
|
||||
RuleBasedCollator( const UnicodeString& rules,
|
||||
ErrorCode& status);
|
||||
|
||||
/** Destructor
|
||||
*/
|
||||
virtual ~RuleBasedCollator();
|
||||
|
||||
/**
|
||||
* Returns true if "other" is the same as "this".
|
||||
*/
|
||||
virtual t_bool operator==(const Collator& other) const;
|
||||
|
||||
/**
|
||||
* Returns true if "other" is not the same as "this".
|
||||
*/
|
||||
virtual t_bool operator!=(const Collator& other) const;
|
||||
|
||||
/**
|
||||
* Makes a shallow copy of the object. The caller owns the returned object.
|
||||
* @return the cloned object.
|
||||
*/
|
||||
virtual Collator* clone() const;
|
||||
|
||||
/**
|
||||
* Fills in the copy of the object.
|
||||
*/
|
||||
virtual void copy(RuleBasedCollator& copyInto) const;
|
||||
|
||||
/**
|
||||
* Creates a collation element iterator for the source string. The
|
||||
* caller of this method is responsible for the memory management of
|
||||
* the return pointer.
|
||||
* @param source the source string.
|
||||
* @return the collation element iterator of the source string using this as
|
||||
* the based collator.
|
||||
*/
|
||||
CollationElementIterator* createCollationElementIterator(const UnicodeString& source) const;
|
||||
|
||||
/**
|
||||
* The following method is obsolete in our current APIs. Some methods
|
||||
* were renamed in JDK 1.1. The older versions of the methods will be kept
|
||||
* around for compatibility but will be made obsolete in the future.
|
||||
*/
|
||||
|
||||
// From createInstance
|
||||
CollationElementIterator* createIterator(const UnicodeString& source) const;
|
||||
/**
|
||||
* Compares a range of character data stored in two different strings
|
||||
* based on the collation rules. Returns
|
||||
* information about whether a string is less than, greater than or
|
||||
* equal to another string in a language.
|
||||
* This can be overriden in a subclass.
|
||||
* @param source the source string.
|
||||
* @param target the target string to be compared with the source stirng.
|
||||
* @return the comparison result. GREATER if the source string is greater
|
||||
* than the target string, LESS if the source is less than the target. Otherwise,
|
||||
* returns EQUAL.
|
||||
*/
|
||||
virtual EComparisonResult compare( const UnicodeString& source,
|
||||
const UnicodeString& target) const;
|
||||
|
||||
|
||||
//[update Bertrand A. DAMIBA 02/10/98]
|
||||
/**
|
||||
* Compares a range of character data stored in two different strings
|
||||
* based on the collation rules up to the specified length. Returns
|
||||
* information about whether a string is less than, greater than or
|
||||
* equal to another string in a language.
|
||||
* This can be overriden in a subclass.
|
||||
* @param source the source string.
|
||||
* @param target the target string to be compared with the source string.
|
||||
* @param length compares up to the specified length
|
||||
* @return the comparison result. GREATER if the source string is greater
|
||||
* than the target string, LESS if the source is less than the target. Otherwise,
|
||||
* returns EQUAL.
|
||||
*/
|
||||
virtual EComparisonResult compare( const UnicodeString& source,
|
||||
const UnicodeString& target,
|
||||
t_int32 length) const;
|
||||
|
||||
//[end of update Bertrand A. DAMIBA 02/10/98]
|
||||
|
||||
/** Transforms a specified region of the string into a series of characters
|
||||
* that can be compared with CollationKey.compare.
|
||||
* This overrides Collator::getCollationKey. It can be overriden
|
||||
* in a subclass.
|
||||
* @param source the source string.
|
||||
* @param key the transformed key of the source string.
|
||||
* @param status the error code status.
|
||||
* @return the transformed key.
|
||||
*/
|
||||
virtual CollationKey& getCollationKey( const UnicodeString& source,
|
||||
CollationKey& key,
|
||||
ErrorCode& status) const;
|
||||
/**
|
||||
* Transforms the string into a unsigned short array that can be compared,
|
||||
* the caller owns the returned array.
|
||||
* <p>If the source string is null, a null collation key will be returned.
|
||||
* @param source the source string to be transformed into a sort key.
|
||||
* @param count returns the number of elements in the returned array.
|
||||
* @return the collation key value array of the string based on the collation rules.
|
||||
* @see CollationKey#compare
|
||||
*/
|
||||
virtual UniChar* createCollationKeyValues( const UnicodeString& source,
|
||||
t_int32& count,
|
||||
ErrorCode& status) const;
|
||||
/**
|
||||
* Generates the hash code for the rule-based collation object.
|
||||
* @return the hash code.
|
||||
*/
|
||||
virtual t_int32 hashCode() const;
|
||||
|
||||
/**
|
||||
* Gets the table-based rules for the collation object.
|
||||
* @return returns the collation rules that the table collation object
|
||||
* was created from.
|
||||
*/
|
||||
const UnicodeString& getRules() const;
|
||||
|
||||
/**
|
||||
* Returns a unique class ID POLYMORPHICALLY. Pure virtual override.
|
||||
* This method is to implement a simple version of RTTI, since not all
|
||||
* C++ compilers support genuine RTTI. Polymorphic operator==() and
|
||||
* clone() methods call this method.
|
||||
*
|
||||
* @return The class ID for this object. All objects of a
|
||||
* given class have the same class ID. Objects of
|
||||
* other classes have different class IDs.
|
||||
*/
|
||||
virtual ClassID getDynamicClassID() const
|
||||
{ return RuleBasedCollator::getStaticClassID(); }
|
||||
|
||||
|
||||
/**
|
||||
* Returns the class ID for this class. This is useful only for
|
||||
* comparing to a return value from getDynamicClassID(). For example:
|
||||
*
|
||||
* Base* polymorphic_pointer = createPolymorphicObject();
|
||||
* if (polymorphic_pointer->getDynamicClassID() ==
|
||||
* Derived::getStaticClassID()) ...
|
||||
*
|
||||
* @return The class ID for all objects of this class.
|
||||
*/
|
||||
static ClassID getStaticClassID() { return (ClassID)&fgClassID; }
|
||||
|
||||
|
||||
protected:
|
||||
/** Copy constructor
|
||||
*/
|
||||
RuleBasedCollator(const RuleBasedCollator& other);
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*/
|
||||
const RuleBasedCollator& operator=(const RuleBasedCollator& other);
|
||||
|
||||
/*****************************************************************************
|
||||
* PRIVATE
|
||||
*****************************************************************************/
|
||||
private:
|
||||
static char fgClassID;
|
||||
friend class CollationElementIterator;
|
||||
|
||||
// Collator ONLY needs access to RuleBasedCollator(const Locale&, ErrorCode&)
|
||||
friend class Collator;
|
||||
|
||||
// TableCollationData ONLY needs access to UNMAPPED
|
||||
friend class TableCollationData;
|
||||
|
||||
|
||||
/** Default constructor
|
||||
*/
|
||||
RuleBasedCollator();
|
||||
|
||||
/**
|
||||
* Create a table-based collation object with the given rules.
|
||||
* @see RuleBasedCollator#RuleBasedCollator
|
||||
* @exception FormatException If the rules format is incorrect.
|
||||
*/
|
||||
void build( const UnicodeString& rules,
|
||||
ErrorCode& success);
|
||||
|
||||
/**
|
||||
* Look up for unmapped values in the expanded character table.
|
||||
*/
|
||||
void commit();
|
||||
/**
|
||||
* Increment of the last order based on the collation strength.
|
||||
* @param s the collation strength.
|
||||
* @param lastOrder the last collation order.
|
||||
* @return the new collation order.
|
||||
*/
|
||||
t_int32 increment( Collator::ECollationStrength s,
|
||||
t_int32 lastOrder);
|
||||
/**
|
||||
* Adds a character and its designated order into the collation table.
|
||||
* @param ch the Unicode character,
|
||||
* @param s the collation strength.
|
||||
* @param status the error code status.
|
||||
*/
|
||||
void addOrder( UniChar ch,
|
||||
Collator::ECollationStrength s,
|
||||
ErrorCode& status);
|
||||
/**
|
||||
* Adds the expanding string into the collation table, for example, a-umlaut in German.
|
||||
* @param groupChars the contracting characters.
|
||||
* @param expChars the expanding characters.
|
||||
* @param s the collation strength
|
||||
* @param status the error code status.
|
||||
*/
|
||||
void addExpandOrder(const UnicodeString& groupChars,
|
||||
const UnicodeString& expChars,
|
||||
Collator::ECollationStrength s,
|
||||
ErrorCode& status);
|
||||
/**
|
||||
* Adds the contracting string into the collation table, for example, ch in Spanish.
|
||||
* @param groupChars the contracting characters.
|
||||
* @param s the collation strength.
|
||||
* @param status the error code status.
|
||||
*/
|
||||
void addContractOrder(const UnicodeString& groupChars,
|
||||
Collator::ECollationStrength s,
|
||||
ErrorCode& status);
|
||||
/**
|
||||
* Gets the entry of list of the contracting string in the collation
|
||||
* table.
|
||||
* @param ch the starting character of the contracting string
|
||||
* @return the entry of contracting element which starts with the specified
|
||||
* character in the list of contracting elements.
|
||||
*/
|
||||
/* changed to getContractValuesFromUniChar to avoid type signature
|
||||
clashes on some UNIX platforms. Only happens with NSPR 1.0 <tague>
|
||||
*/
|
||||
VectorOfPToContractElement*
|
||||
getContractValuesFromUniChar( UniChar ch) const;
|
||||
/**
|
||||
* Ges the entry of list of the contracting string in the collation
|
||||
* table.
|
||||
* @param n the index of the contract character list
|
||||
* @return the entry of the contracting element of the specified index in the
|
||||
* list.
|
||||
*/
|
||||
VectorOfPToContractElement*
|
||||
getContractValues( t_int32 index) const;
|
||||
/**
|
||||
* Gets the entry of list of the expanding string that starts with the specified
|
||||
* character in the collation table.
|
||||
* @param ch the starting character of the expanding string
|
||||
* @return the entry of the expanding-char element which starts with the
|
||||
* specified character.
|
||||
*/
|
||||
VectorOfInt* getExpandValuesFromUniChar( UniChar ch) const;
|
||||
/**
|
||||
* Gets the entry of value list of the expanding string in the collation
|
||||
* table at the specified index.
|
||||
* @param idx the index of the expanding string value list
|
||||
* @return the entry of the expanding-char element of the specified index in
|
||||
* the list.
|
||||
*/
|
||||
VectorOfInt* getExpandValues( t_int32 index) const;
|
||||
/**
|
||||
* Gets the comarison order of a character from the collation table.
|
||||
* @param ch the Unicode character
|
||||
* @return the comparison order of a character.
|
||||
*/
|
||||
t_int32 getUnicodeOrder( UniChar ch) const;
|
||||
|
||||
/**
|
||||
* Gets the comarison order of a character from the collation table.
|
||||
* @param list the contracting element table.
|
||||
* @param name the contracting char string.
|
||||
* @return the comparison order of the contracting character.
|
||||
*/
|
||||
t_int32 getEntry( VectorOfPToContractElement* list,
|
||||
const UnicodeString& name);
|
||||
/**
|
||||
* Check for the secondary and tertiary differences of source and
|
||||
* target comparison orders.
|
||||
* @param sOrder source collation order.
|
||||
* @param tOrder target collation order.
|
||||
* @param result the current collation result
|
||||
* @param s the current collation strength
|
||||
* @param skipSecCheck whether to skip the secondary check.
|
||||
* @return Collator.LESS if sOrder < tOrder; EQUAL if sOrder == tOrder;
|
||||
* Collator.GREATER if sOrder > tOrder.
|
||||
*/
|
||||
Collator::EComparisonResult
|
||||
checkSecTerDiff( t_int32 sOrder,
|
||||
t_int32 tOrder,
|
||||
Collator::EComparisonResult result,
|
||||
Collator::ECollationStrength& s,
|
||||
t_bool skipSecCheck = FALSE) const;
|
||||
|
||||
/**
|
||||
* Flattens the given object persistently to a file. The file name
|
||||
* argument should be a path name that can be passed directly to the
|
||||
* underlying OS. Once a RuleBasedCollator has been written to a file,
|
||||
* it can be resurrected by calling the RuleBasedCollator(const char*)
|
||||
* constructor, which operates very quickly.
|
||||
* @param fileName the output file name.
|
||||
* @return TRUE if writing to the file was successful, FALSE otherwise.
|
||||
*/
|
||||
t_bool writeToFile(const char* fileName) const; // True on success
|
||||
|
||||
/**
|
||||
* Add this table collation to the cache. This involves adding the
|
||||
* enclosed TableCollationData to the cache, and then marking our
|
||||
* pointer as "not owned" by setting dataIsOwned to false.
|
||||
* @param key the unique that represents this collation data object.
|
||||
*/
|
||||
void addToCache( const UnicodeString& key);
|
||||
|
||||
/**
|
||||
* RuleBasedCollator constructor. This constructor takes a locale. The only
|
||||
* caller of this class should be Collator::createDefault(). If createDefault()
|
||||
* happens to know that the requested locale's collation is implemented as
|
||||
* a RuleBasedCollator, it can then call this constructor. OTHERWISE IT SHOULDN'T,
|
||||
* since this constructor ALWAYS RETURNS A VALID COLLATION TABLE. It does this
|
||||
* by falling back to defaults.
|
||||
*/
|
||||
RuleBasedCollator( const Locale& desiredLocale,
|
||||
ErrorCode& status);
|
||||
/**
|
||||
* Internal constructFromXyx() methods. These methods do object construction
|
||||
* from various sources. They act like assignment operators; whatever used
|
||||
* to be in this object is discarded. <P>FROM RULES. This constructor turns
|
||||
* around and calls build(). <P>FROM CACHE. This constructor tries to get the
|
||||
* requested cached TableCollationData object, and wrap us around it. <P>FROM FILE.
|
||||
* There are two constructors named constructFromFile(). One takes a const char*:
|
||||
* this is a path name to be passed directly to the host OS, where a flattened
|
||||
* table collation (produced by writeToFile()) resides. The other method takes
|
||||
* a Locale, and a UnicodeString locale file name. The distinction is this:
|
||||
* the Locale is the locale we are seeking. The file name is the name of the
|
||||
* data file (either binary, as produced by writeToFile(), or ASCII, as read
|
||||
* by ResourceBundle). Within the file, if it is found, the method will look
|
||||
* for the given Locale.
|
||||
*/
|
||||
void constructFromRules( const UnicodeString& rules,
|
||||
ErrorCode& status);
|
||||
void constructFromFile( const Locale& locale,
|
||||
const UnicodeString& localeFileName,
|
||||
t_bool tryBinaryFile,
|
||||
ErrorCode& status);
|
||||
void constructFromFile( const char* fileName,
|
||||
ErrorCode& status);
|
||||
void constructFromCache( const UnicodeString& key,
|
||||
ErrorCode& status);
|
||||
|
||||
/**
|
||||
* The streamIn and streamOut methods read and write objects of this
|
||||
* class as binary, platform-dependent data in the iostream. The stream
|
||||
* must be in ios::binary mode for this to work. These methods are not
|
||||
* intended for general public use; they are used by the framework to improve
|
||||
* performance by storing certain objects in binary files.
|
||||
*/
|
||||
void streamIn(FILE* is);
|
||||
void streamOut(FILE* os) const;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Internal Static Utility Methods
|
||||
/**
|
||||
* Creates the path name with given information.
|
||||
* @param prefix the prefix of the file name.
|
||||
* @param name the actual file name.
|
||||
* @param suffix the suffix of the file name.
|
||||
* @return the generated file name.
|
||||
*/
|
||||
static char* createPathName( const UnicodeString& prefix,
|
||||
const UnicodeString& name,
|
||||
const UnicodeString& suffix);
|
||||
|
||||
/**
|
||||
* Chops off the last portion of the locale name. For example, from "en_US_CA"
|
||||
* to "en_US" and "en_US" to "en".
|
||||
* @param localeName the locale name.
|
||||
*/
|
||||
static void chopLocale(UnicodeString& localeName);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Constants
|
||||
|
||||
static const t_int32 UNMAPPED;
|
||||
static const t_int32 CHARINDEX; // need look up in .commit()
|
||||
static const t_int32 EXPANDCHARINDEX; // Expand index follows
|
||||
static const t_int32 CONTRACTCHARINDEX; // contract indexes follow
|
||||
|
||||
static const t_int32 PRIMARYORDERINCREMENT;
|
||||
static const t_int32 MAXIGNORABLE;
|
||||
static const t_int32 SECONDARYORDERINCREMENT;
|
||||
static const t_int32 TERTIARYORDERINCREMENT;
|
||||
static const t_int32 PRIMARYORDERMASK;
|
||||
static const t_int32 SECONDARYORDERMASK;
|
||||
static const t_int32 TERTIARYORDERMASK;
|
||||
static const t_int32 SECONDARYRESETMASK;
|
||||
static const t_int32 IGNORABLEMASK;
|
||||
static const t_int32 PRIMARYDIFFERENCEONLY;
|
||||
static const t_int32 SECONDARYDIFFERENCEONLY;
|
||||
static const t_int32 PRIMARYORDERSHIFT;
|
||||
static const t_int32 SECONDARYORDERSHIFT;
|
||||
static const t_int32 SORTKEYOFFSET;
|
||||
static const t_int32 CONTRACTCHAROVERFLOW;
|
||||
|
||||
static const t_int16 FILEID;
|
||||
|
||||
static UnicodeString DEFAULTRULES;
|
||||
|
||||
static const char* kFilenameSuffix;
|
||||
static const char* kResourceBundleSuffix;
|
||||
|
||||
static const t_uint32 kCompactionCycle;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Data Members
|
||||
|
||||
t_bool isOverIgnore;
|
||||
t_int32 currentOrder;
|
||||
UniChar lastChar;
|
||||
MergeCollation* mPattern;
|
||||
UnicodeString sbuffer;
|
||||
UnicodeString tbuffer;
|
||||
UnicodeString key;
|
||||
CollationElementIterator *sourceCursor;
|
||||
CollationElementIterator *targetCursor;
|
||||
t_bool dataIsOwned;
|
||||
TableCollationData* data;
|
||||
};
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
inline t_bool
|
||||
RuleBasedCollator::operator!=(const Collator& other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,648 @@
|
|||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1996, 1997 *
|
||||
* (C) Copyright International Business Machines Corporation, 1996, 1997 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
*/
|
||||
// Copyright (C) 1996-1997 Taligent, Inc. All rights reserved.
|
||||
//
|
||||
// FILE NAME : unicode.h
|
||||
//
|
||||
// CREATED
|
||||
// Wednesday, December 11, 1996
|
||||
//
|
||||
// CREATED BY
|
||||
// Helena Shih
|
||||
//
|
||||
//
|
||||
//********************************************************************************************
|
||||
|
||||
|
||||
|
||||
#ifndef _UNICODE
|
||||
#define _UNICODE
|
||||
|
||||
#include "ptypes.h"
|
||||
class CompactByteArray;
|
||||
class CompactShortArray;
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The Unicode class allows you to query the properties associated with individual
|
||||
* Unicode character values.
|
||||
* <p>
|
||||
* The Unicode character information, provided implicitly by the
|
||||
* Unicode character encoding standard, includes information about the sript
|
||||
* (for example, symbols or control characters) to which the character belongs,
|
||||
* as well as semantic information such as whether a character is a digit or
|
||||
* uppercase, lowercase, or uncased.
|
||||
* <P>
|
||||
* @subclassing Do not subclass.
|
||||
*/
|
||||
class T_UTILITY_API Unicode
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* The minimum value a UniChar can have. The lowest value a
|
||||
* UniChar can have is 0x0000.
|
||||
*/
|
||||
static const UniChar MIN_VALUE;
|
||||
|
||||
/**
|
||||
* The maximum value a UniChar can have. The greatest value a
|
||||
* UniChar can have is 0xffff.
|
||||
*/
|
||||
static const UniChar MAX_VALUE;
|
||||
|
||||
/**
|
||||
* Public data for enumerated Unicode general category types
|
||||
*/
|
||||
|
||||
enum EUnicodeGeneralTypes
|
||||
{
|
||||
UNASSIGNED = 0,
|
||||
UPPERCASE_LETTER = 1,
|
||||
LOWERCASE_LETTER = 2,
|
||||
TITLECASE_LETTER = 3,
|
||||
MODIFIER_LETTER = 4,
|
||||
OTHER_LETTER = 5,
|
||||
NON_SPACING_MARK = 6,
|
||||
ENCLOSING_MARK = 7,
|
||||
COMBINING_SPACING_MARK = 8,
|
||||
DECIMAL_DIGIT_NUMBER = 9,
|
||||
LETTER_NUMBER = 10,
|
||||
OTHER_NUMBER = 11,
|
||||
SPACE_SEPARATOR = 12,
|
||||
LINE_SEPARATOR = 13,
|
||||
PARAGRAPH_SEPARATOR = 14,
|
||||
CONTROL = 15,
|
||||
FORMAT = 16,
|
||||
PRIVATE_USE = 17,
|
||||
SURROGATE = 18,
|
||||
DASH_PUNCTUATION = 19,
|
||||
START_PUNCTUATION = 20,
|
||||
END_PUNCTUATION = 21,
|
||||
CONNECTOR_PUNCTUATION = 22,
|
||||
OTHER_PUNCTUATION = 23,
|
||||
MATH_SYMBOL = 24,
|
||||
CURRENCY_SYMBOL = 25,
|
||||
MODIFIER_SYMBOL = 26,
|
||||
OTHER_SYMBOL = 27,
|
||||
GENERAL_TYPES_COUNT = 28
|
||||
};
|
||||
|
||||
/**
|
||||
* This specifies the language directional property of a character set.
|
||||
*/
|
||||
enum EDirectionProperty {
|
||||
LEFT_TO_RIGHT = 0,
|
||||
RIGHT_TO_LEFT = 1,
|
||||
EUROPEAN_NUMBER = 2,
|
||||
EUROPEAN_NUMBER_SEPARATOR = 3,
|
||||
EUROPEAN_NUMBER_TERMINATOR = 4,
|
||||
ARABIC_NUMBER = 5,
|
||||
COMMON_NUMBER_SEPARATOR = 6,
|
||||
BLOCK_SEPARATOR = 7,
|
||||
SEGMENT_SEPARATOR = 8,
|
||||
WHITE_SPACE_NEUTRAL = 9,
|
||||
OTHER_NEUTRAL = 10
|
||||
};
|
||||
|
||||
/**
|
||||
* Values returned by the getCellWidth() function.
|
||||
* @see Unicode#getCellWidth
|
||||
*/
|
||||
enum ECellWidths
|
||||
{
|
||||
ZERO_WIDTH = 0,
|
||||
HALF_WIDTH = 1,
|
||||
FULL_WIDTH = 2,
|
||||
NEUTRAL = 3
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines whether the specified UniChar is a lowercase character
|
||||
* according to Unicode 2.0.14.
|
||||
*
|
||||
* @param ch the character to be tested
|
||||
* @return true if the character is lowercase; false otherwise.
|
||||
*
|
||||
* @see Unicode#isUpperCase
|
||||
* @see Unicode#isTitleCase
|
||||
* @see Unicode#toLowerCase
|
||||
*/
|
||||
static t_bool isLowerCase( UniChar ch);
|
||||
/**
|
||||
* Determines whether the specified character is an uppercase character
|
||||
* according to Unicode 2.0.14.
|
||||
*
|
||||
* @param ch the character to be tested
|
||||
* @return true if the character is uppercase; false otherwise.
|
||||
* @see Unicode#isLowerCase
|
||||
* @see Unicode#isTitleCase
|
||||
* @see Unicode#toUpperCase
|
||||
*/
|
||||
|
||||
static t_bool isUpperCase( UniChar ch);
|
||||
|
||||
/**
|
||||
* Determines whether the specified character is a titlecase character
|
||||
* according to Unicode 2.0.14.
|
||||
*
|
||||
* @param ch the character to be tested
|
||||
* @return true if the character is titlecase; false otherwise.
|
||||
* @see Unicode#isUpperCase
|
||||
* @see Unicode#isLowerCase
|
||||
* @see Unicode#toTitleCase
|
||||
*/
|
||||
|
||||
static t_bool isTitleCase( UniChar ch);
|
||||
|
||||
/**
|
||||
* Determines whether the specified character is a digit according to Unicode
|
||||
* 2.0.14.
|
||||
*
|
||||
* @param ch the character to be tested
|
||||
* @return true if the character is a digit; false otherwise.
|
||||
*/
|
||||
|
||||
static t_bool isDigit( UniChar ch) ;
|
||||
|
||||
/**
|
||||
* Determines whether the specified numeric value is actually a defined character
|
||||
* according to Unicode 2.0.14.
|
||||
*
|
||||
* @param ch the character to be tested
|
||||
* @return true if the character has a defined Unicode meaning; false otherwise.
|
||||
*
|
||||
* @see Unicode#isDigit
|
||||
* @see Unicode#isLetter
|
||||
* @see Unicode#isLetterOrDigit
|
||||
* @see Unicode#isUpperCase
|
||||
* @see Unicode#isLowerCase
|
||||
* @see Unicode#isTitleCase
|
||||
*/
|
||||
|
||||
static t_bool isDefined(UniChar ch);
|
||||
|
||||
/**
|
||||
* Determines whether the specified character is a control character according
|
||||
* to Unicode 2.0.14.
|
||||
*
|
||||
* @param ch the character to be tested
|
||||
* @return true if the Unicode character is a control character; false otherwise.
|
||||
*
|
||||
* @see Unicode#isPrintable
|
||||
*/
|
||||
static t_bool isControl(UniChar ch);
|
||||
|
||||
/**
|
||||
* Determines whether the specified character is a printable character according
|
||||
* to Unicode 2.0.14.
|
||||
*
|
||||
* @param ch the character to be tested
|
||||
* @return true if the Unicode character is a printable character; false otherwise.
|
||||
*
|
||||
* @see Unicode#isControl
|
||||
*/
|
||||
static t_bool isPrintable(UniChar ch);
|
||||
|
||||
/**
|
||||
* Determines whether the specified character is of the base form according
|
||||
* to Unicode 2.0.14.
|
||||
*
|
||||
* @param ch the character to be tested
|
||||
* @return true if the Unicode character is of the base form; false otherwise.
|
||||
*
|
||||
* @see Unicode#isLetter
|
||||
* @see Unicode#isDigit
|
||||
*/
|
||||
|
||||
static t_bool isBaseForm(UniChar ch);
|
||||
/**
|
||||
* Determines whether the specified character is a letter
|
||||
* according to Unicode 2.0.14.
|
||||
*
|
||||
* @param ch the character to be tested
|
||||
* @return true if the character is a letter; false otherwise.
|
||||
*
|
||||
*
|
||||
* @see Unicode#isDigit
|
||||
* @see Unicode#isLetterOrDigit
|
||||
* @see Unicode#isUpperCase
|
||||
* @see Unicode#isLowerCase
|
||||
* @see Unicode#isTitleCase
|
||||
*/
|
||||
static t_bool isLetter(UniChar ch);
|
||||
|
||||
/**
|
||||
* A convenience method for determining if a Unicode character
|
||||
* is allowed as the first character in a Java identifier.
|
||||
* <P>
|
||||
* A character may start a Java identifier if and only if
|
||||
* it is one of the following:
|
||||
* <ul>
|
||||
* <li> a letter
|
||||
* <li> a currency symbol (such as "$")
|
||||
* <li> a connecting punctuation symbol (such as "_").
|
||||
* </ul>
|
||||
*
|
||||
* @param ch the Unicode character.
|
||||
* @return TRUE if the character may start a Java identifier;
|
||||
* FALSE otherwise.
|
||||
* @see isJavaIdentifierPart
|
||||
* @see isLetter
|
||||
* @see isUnicodeIdentifierStart
|
||||
*/
|
||||
static t_bool isJavaIdentifierStart(UniChar ch);
|
||||
|
||||
/**
|
||||
* A convenience method for determining if a Unicode character
|
||||
* may be part of a Java identifier other than the starting
|
||||
* character.
|
||||
* <P>
|
||||
* A character may be part of a Java identifier if and only if
|
||||
* it is one of the following:
|
||||
* <ul>
|
||||
* <li> a letter
|
||||
* <li> a currency symbol (such as "$")
|
||||
* <li> a connecting punctuation character (such as "_").
|
||||
* <li> a digit
|
||||
* <li> a numeric letter (such as a Roman numeral character)
|
||||
* <li> a combining mark
|
||||
* <li> a non-spacing mark
|
||||
* <li> an ignorable control character
|
||||
* </ul>
|
||||
*
|
||||
* @param ch the Unicode character.
|
||||
* @return TRUE if the character may be part of a Unicode identifier;
|
||||
* FALSE otherwise.
|
||||
* @see isIdentifierIgnorable
|
||||
* @see isJavaIdentifierStart
|
||||
* @see isLetter
|
||||
* @see isDigit
|
||||
* @see isUnicodeIdentifierPart
|
||||
*/
|
||||
static t_bool isJavaIdentifierPart(UniChar ch);
|
||||
|
||||
/**
|
||||
* A convenience method for determining if a Unicode character
|
||||
* is allowed to start in a Unicode identifier.
|
||||
* A character may start a Unicode identifier if and only if
|
||||
* it is a letter.
|
||||
*
|
||||
* @param ch the Unicode character.
|
||||
* @return TRUE if the character may start a Unicode identifier;
|
||||
* FALSE otherwise.
|
||||
* @see isJavaIdentifierStart
|
||||
* @see isLetter
|
||||
* @see isUnicodeIdentifierPart
|
||||
*/
|
||||
static t_bool isUnicodeIdentifierStart(UniChar ch);
|
||||
|
||||
/**
|
||||
* A convenience method for determining if a Unicode character
|
||||
* may be part of a Unicode identifier other than the starting
|
||||
* character.
|
||||
* <P>
|
||||
* A character may be part of a Unicode identifier if and only if
|
||||
* it is one of the following:
|
||||
* <ul>
|
||||
* <li> a letter
|
||||
* <li> a connecting punctuation character (such as "_").
|
||||
* <li> a digit
|
||||
* <li> a numeric letter (such as a Roman numeral character)
|
||||
* <li> a combining mark
|
||||
* <li> a non-spacing mark
|
||||
* <li> an ignorable control character
|
||||
* </ul>
|
||||
*
|
||||
* @param ch the Unicode character.
|
||||
* @return TRUE if the character may be part of a Unicode identifier;
|
||||
* FALSE otherwise.
|
||||
* @see isIdentifierIgnorable
|
||||
* @see isJavaIdentifierPart
|
||||
* @see isLetterOrDigit
|
||||
* @see isUnicodeIdentifierStart
|
||||
*/
|
||||
static t_bool isUnicodeIdentifierPart(UniChar ch);
|
||||
|
||||
/**
|
||||
* A convenience method for determining if a Unicode character
|
||||
* should be regarded as an ignorable character in a Java
|
||||
* identifier or a Unicode identifier.
|
||||
* <P>
|
||||
* The following Unicode characters are ignorable in a Java identifier
|
||||
* or a Unicode identifier:
|
||||
* <table>
|
||||
* <tr><td>0x0000 through 0x0008,</td>
|
||||
* <td>ISO control characters that</td></tr>
|
||||
* <tr><td>0x000E through 0x001B,</td> <td>are not whitespace</td></tr>
|
||||
* <tr><td>and 0x007F through 0x009F</td></tr>
|
||||
* <tr><td>0x200C through 0x200F</td> <td>join controls</td></tr>
|
||||
* <tr><td>0x200A through 0x200E</td> <td>bidirectional controls</td></tr>
|
||||
* <tr><td>0x206A through 0x206F</td> <td>format controls</td></tr>
|
||||
* <tr><td>0xFEFF</td> <td>zero-width no-break space</td></tr>
|
||||
* </table>
|
||||
*
|
||||
* @param ch the Unicode character.
|
||||
* @return TRUE if the character may be part of a Unicode identifier;
|
||||
* FALSE otherwise.
|
||||
* @see isJavaIdentifierPart
|
||||
* @see isUnicodeIdentifierPart
|
||||
*/
|
||||
static t_bool isIdentifierIgnorable(UniChar ch);
|
||||
|
||||
/**
|
||||
* The given character is mapped to its lowercase equivalent according to
|
||||
* Unicode 2.0.14; if the character has no lowercase equivalent, the character
|
||||
* itself is returned.
|
||||
* <P>
|
||||
* A character has a lowercase equivalent if and only if a lowercase mapping
|
||||
* is specified for the character in the Unicode 2.0 attribute table.
|
||||
* <P>
|
||||
* Unicode::toLowerCase() only deals with the general letter case conversion.
|
||||
* For language specific case conversion behavior, use UnicodeString::toLower().
|
||||
* For example, the case conversion for dot-less i and dotted I in Turkish,
|
||||
* or for final sigma in Greek.
|
||||
*
|
||||
* @param ch the character to be converted
|
||||
* @return the lowercase equivalent of the character, if any;
|
||||
* otherwise the character itself.
|
||||
*
|
||||
* @see UnicodeString#toLower
|
||||
* @see Unicode#isLowerCase
|
||||
* @see Unicode#isUpperCase
|
||||
* @see Unicode#toUpperCase
|
||||
* @see Unicode#toTitleCase
|
||||
*/
|
||||
static UniChar toLowerCase(UniChar ch);
|
||||
|
||||
/**
|
||||
* The given character is mapped to its uppercase equivalent according to Unicode
|
||||
* 2.0.14; if the character has no uppercase equivalent, the character itself is
|
||||
* returned.
|
||||
* <P>
|
||||
* Unicode::toUpperCase() only deals with the general letter case conversion.
|
||||
* For language specific case conversion behavior, use UnicodeString::toUpper().
|
||||
* For example, the case conversion for dot-less i and dotted I in Turkish,
|
||||
* or ess-zed (i.e., "sharp S") in German.
|
||||
*
|
||||
* @param ch the character to be converted
|
||||
* @return the uppercase equivalent of the character, if any;
|
||||
* otherwise the character itself.
|
||||
*
|
||||
* @see UnicodeString#toUpper
|
||||
* @see Unicode#isUpperCase
|
||||
* @see Unicode#isLowerCase
|
||||
* @see Unicode#toLowerCase
|
||||
* @see Unicode#toTitleCase
|
||||
*/
|
||||
static UniChar toUpperCase(UniChar ch);
|
||||
|
||||
/**
|
||||
* The given character is mapped to its titlecase equivalent according to Unicode
|
||||
* 2.0.14. There are only four Unicode characters that are truly titlecase forms
|
||||
* that are distinct from uppercase forms. As a rule, if a character has no
|
||||
* true titlecase equivalent, its uppercase equivalent is returned.
|
||||
* <P>
|
||||
* A character has a titlecase equivalent if and only if a titlecase mapping
|
||||
* is specified for the character in the Unicode 2.0.14 data.
|
||||
*
|
||||
* @param ch the character to be converted
|
||||
* @return the titlecase equivalent of the character, if any;
|
||||
* otherwise the character itself.
|
||||
* @see Unicode#isTitleCase
|
||||
* @see Unicode#toUpperCase
|
||||
* @see Unicode#toLowerCase
|
||||
*/
|
||||
static UniChar toTitleCase(UniChar ch);
|
||||
|
||||
/**
|
||||
* Determines if the specified character is a Unicode space character
|
||||
* according to Unicode 2.0.14.
|
||||
*
|
||||
* @param ch the character to be tested
|
||||
* @return true if the character is a space character; false otherwise.
|
||||
*/
|
||||
static t_bool isSpaceChar(UniChar ch);
|
||||
|
||||
/**
|
||||
* Returns a value indicating a character category according to Unicode
|
||||
* 2.0.14.
|
||||
* @param ch the character to be tested
|
||||
* @return a value of type int, the character category.
|
||||
* @see Unicode#UNASSIGNED
|
||||
* @see Unicode#UPPERCASE_LETTER
|
||||
* @see Unicode#LOWERCASE_LETTER
|
||||
* @see Unicode#TITLECASE_LETTER
|
||||
* @see Unicode#MODIFIER_LETTER
|
||||
* @see Unicode#OTHER_LETTER
|
||||
* @see Unicode#NON_SPACING_MARK
|
||||
* @see Unicode#ENCLOSING_MARK
|
||||
* @see Unicode#COMBINING_SPACING_MARK
|
||||
* @see Unicode#DECIMAL_DIGIT_NUMBER
|
||||
* @see Unicode#OTHER_NUMBER
|
||||
* @see Unicode#SPACE_SEPARATOR
|
||||
* @see Unicode#LINE_SEPARATOR
|
||||
* @see Unicode#PARAGRAPH_SEPARATOR
|
||||
* @see Unicode#CONTROL
|
||||
* @see Unicode#PRIVATE_USE
|
||||
* @see Unicode#SURROGATE
|
||||
* @see Unicode#DASH_PUNCTUATION
|
||||
* @see Unicode#OPEN_PUNCTUATION
|
||||
* @see Unicode#CLOSE_PUNCTUATION
|
||||
* @see Unicode#CONNECTOR_PUNCTUATION
|
||||
* @see Unicode#OTHER_PUNCTUATION
|
||||
* @see Unicode#LETTER_NUMBER
|
||||
* @see Unicode#MATH_SYMBOL
|
||||
* @see Unicode#CURRENCY_SYMBOL
|
||||
* @see Unicode#MODIFIER_SYMBOL
|
||||
* @see Unicode#OTHER_SYMBOL
|
||||
*/
|
||||
static t_int8 getType(UniChar ch);
|
||||
|
||||
/**
|
||||
* Returns the linguistic direction property of a character.
|
||||
* <P>
|
||||
* Returns the linguistic direction property of a character.
|
||||
* For example, 0x0041 (letter A) has the LEFT_TO_RIGHT directional
|
||||
* property.
|
||||
* @see #EDirectionProperty
|
||||
*/
|
||||
static EDirectionProperty characterDirection(UniChar ch);
|
||||
|
||||
/**
|
||||
* Returns a value indicating the display-cell width of the character
|
||||
* when used in Asian text, according to the Unicode standard (see p. 6-130
|
||||
* of The Unicode Standard, Version 2.0). The results for various characters
|
||||
* are as follows:
|
||||
* <P>
|
||||
* ZERO_WIDTH: Characters which are considered to take up no display-cell space:
|
||||
* control characters
|
||||
* format characters
|
||||
* line and paragraph separators
|
||||
* non-spacing marks
|
||||
* combining Hangul jungseong
|
||||
* combining Hangul jongseong
|
||||
* unassigned Unicode values
|
||||
* <P>
|
||||
* HALF_WIDTH: Characters which take up half a cell in standard Asian text:
|
||||
* all characters in the General Scripts Area except combining Hangul choseong
|
||||
* and the characters called out specifically above as ZERO_WIDTH
|
||||
* alphabetic and Arabic presentation forms
|
||||
* halfwidth CJK punctuation
|
||||
* halfwidth Katakana
|
||||
* halfwidth Hangul Jamo
|
||||
* halfwidth forms, arrows, and shapes
|
||||
* <P>
|
||||
* FULL_WIDTH: Characters which take up a full cell in standard Asian text:
|
||||
* combining Hangul choseong
|
||||
* all characters in the CJK Phonetics and Symbols Area
|
||||
* all characters in the CJK Ideographs Area
|
||||
* all characters in the Hangul Syllables Area
|
||||
* CJK compatibility ideographs
|
||||
* CJK compatibility forms
|
||||
* small form variants
|
||||
* fullwidth ASCII
|
||||
* fullwidth punctuation and currency signs
|
||||
* <P>
|
||||
* NEUTRAL: Characters whose cell width is context-dependent:
|
||||
* all characters in the Symbols Area, except those specifically called out above
|
||||
* all characters in the Surrogates Area
|
||||
* all charcaters in the Private Use Area
|
||||
* <P>
|
||||
* For Korean text, this algorithm should work properly with properly normalized Korean
|
||||
* text. Precomposed Hangul syllables and non-combining jamo are all considered full-
|
||||
* width characters. For combining jamo, we treat we treat choseong (initial consonants)
|
||||
* as double-width characters and junseong (vowels) and jongseong (final consonants)
|
||||
* as non-spacing marks. This will work right in text that uses the precomposed
|
||||
* choseong characters instead of teo choseong characters in a row, and which uses the
|
||||
* choseong filler character at the beginning of syllables that don't have an initial
|
||||
* consonant. The results may be slightly off with Korean text following different
|
||||
* conventions.
|
||||
*/
|
||||
static t_uint16 getCellWidth(UniChar ch);
|
||||
|
||||
static UniChar* toLowerCase(UniChar* ch, t_int32 size);
|
||||
static UniChar* toUpperCase(UniChar* ch, t_int32 size);
|
||||
static int compare(const UniChar* ch, t_int32 size, const UniChar* ch1, t_int32 size1);
|
||||
static int compareIgnoreCase(const UniChar* ch, t_int32 size, const UniChar* ch1, t_int32 size1);
|
||||
static TextOffset indexOf(const UniChar* ch, t_int32 size, const UniChar* character, t_int32 length, TextOffset fromOffset = 0);
|
||||
static TextOffset lastIndexOf(const UniChar* ch, t_int32 size, const UniChar* character, t_int32 length, TextOffset fromOffset = 0);
|
||||
static size_t length(const UniChar* str);
|
||||
static UniChar* copy(const UniChar* str);
|
||||
|
||||
|
||||
//
|
||||
// Netscape Added Methods
|
||||
//
|
||||
|
||||
/**
|
||||
* Releases a UniChar array allocated by one of the Unicode methods.
|
||||
*/
|
||||
static void release(UniChar* buffer);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the first instance of ch in the
|
||||
* Unicode string.
|
||||
* @param str string to search
|
||||
* @param strLength length of str in UniChars
|
||||
* @param ch UniChar to search for
|
||||
*/
|
||||
static const UniChar* strchr(const UniChar* str, size_t strLength, UniChar ch);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the last instance of ch in the
|
||||
* Unicode string.
|
||||
* @param str string to search
|
||||
* @param strLength length of str in UniChars
|
||||
* @param ch UniChar to search for
|
||||
*/
|
||||
static const UniChar* strrchr(const UniChar* str, size_t strLength, UniChar ch);
|
||||
|
||||
/**
|
||||
* Compares two UniChar arrays based on the underlying file system
|
||||
* mode of comparison.
|
||||
* @param source array to be compared
|
||||
* @param sourceLength length of source in UniChars
|
||||
* @param target array to be compared
|
||||
* @param targetLength length of target in UniChars
|
||||
*/
|
||||
static int fileNameCompare(const UniChar* source, size_t sourceLength, const UniChar* target, size_t targetLength);
|
||||
|
||||
/**
|
||||
* Concatenates two UniChar arrays and returns the result in a new buffer
|
||||
* @param str1 first string
|
||||
* @param sourceLength length of str1 in UniChars
|
||||
* @param str2 second string
|
||||
* @param str2Length length of second string
|
||||
*/
|
||||
static UniChar* appendString(const UniChar* str1,size_t str1Length, const UniChar* str2,size_t str2Length);
|
||||
|
||||
/**
|
||||
* Regular Expression-like search through a UniChar string.
|
||||
* @param string string to search
|
||||
* @param stringLength length of string in UniChars
|
||||
* @param expression regular expression (as a C-string)
|
||||
*/
|
||||
static TextOffset regularExpressionSearch(const UniChar* string, size_t stringLength, const char* expression);
|
||||
|
||||
/**
|
||||
* Regular Expression-like search through a UniChar string.
|
||||
* @param source string to search
|
||||
* @param sourceLength length of source in UniChars
|
||||
* @param expression regular expression (as a UniChar)
|
||||
* @param expressionLength length of regular expression in UniChars
|
||||
*/
|
||||
static TextOffset regularExpressionSearch(const UniChar* string, size_t stringLength, const UniChar* expression, size_t expressionLength);
|
||||
|
||||
protected:
|
||||
// These constructors, destructor, and assignment operator must
|
||||
// be protected (not private, as they semantically are) to make
|
||||
// various UNIX compilers happy. [LIU]
|
||||
Unicode();
|
||||
Unicode( const Unicode& other);
|
||||
~Unicode();
|
||||
const Unicode& operator=( const Unicode& other);
|
||||
|
||||
private:
|
||||
static const t_int8 isLetterMask;
|
||||
static const t_uint16 indicies[];
|
||||
static const t_int8 values[];
|
||||
static const t_int32 offsetCount;
|
||||
static const t_uint16 caseIndex[];
|
||||
static const t_int16 caseValues[];
|
||||
static const t_int32 caseCount;
|
||||
static const t_uint16 fCharDirIndices[];
|
||||
static const t_int8 fCharDirValues[];
|
||||
static const t_int32 fCharDirCount;
|
||||
|
||||
static CompactByteArray *tables;
|
||||
static CompactShortArray *ulTables;
|
||||
static CompactByteArray *dirTables;
|
||||
|
||||
static t_bool tablesCreated;
|
||||
static t_bool ulTablesCreated;
|
||||
static t_bool dirTablesCreated;
|
||||
static void createTables();
|
||||
static void createUlTables();
|
||||
static void createDirTables();
|
||||
|
||||
};
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,682 @@
|
|||
/*
|
||||
*****************************************************************************************
|
||||
* *
|
||||
* COPYRIGHT: *
|
||||
* (C) Copyright Taligent, Inc., 1997 *
|
||||
* (C) Copyright International Business Machines Corporation, 1996 *
|
||||
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
|
||||
* US Government Users Restricted Rights - Use, duplication, or disclosure *
|
||||
* restricted by GSA ADP Schedule Contract with IBM Corp. *
|
||||
* *
|
||||
*****************************************************************************************
|
||||
*
|
||||
* FILE NAME : unistring.h
|
||||
*
|
||||
* Modification History:
|
||||
*
|
||||
* Date Name Description
|
||||
* 02/05/97 aliu Added UnicodeString streamIn and streamOut methods.
|
||||
* 03/26/97 aliu Added indexOf(UniChar,).
|
||||
* 04/24/97 aliu Numerous changes per code review.
|
||||
* 05/06/97 helena Added isBogus().
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _UNISTRING
|
||||
#define _UNISTRING
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
#include "ptypes.h"
|
||||
class Locale;
|
||||
|
||||
/**
|
||||
* Simple Unicode string class. This is a simple class that encapsulates a
|
||||
* Unicode string, allowing the user to manipulate it and allowing it to grow
|
||||
* and shrink without the user having to worry about this.
|
||||
* <P>
|
||||
* The char* interfaces on this class work with either the Latin1 (ISO 8859-1)
|
||||
* character set or a host character set. The host character set may be any
|
||||
* 8-bit character set for which TPlatformUtilities::mapHostTo8859_1() and
|
||||
* TPlatformUtilities::map8859_1ToHost() have been defined; the default
|
||||
* implementation maps to and from EBCDIC as defined in RFC 1345. If the
|
||||
* host character set is used, then incoming characters are mapped to Unicode,
|
||||
* and outgoing characters are mapped back to the host character set.
|
||||
* <P>
|
||||
* All inbound transcoding of char* data is done by zero-extending the incoming
|
||||
* characters, and all outbound transcoding is done by truncating the top byte
|
||||
* from the characters.
|
||||
*/
|
||||
#ifdef NLS_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
class T_UTILITY_API UnicodeString {
|
||||
public:
|
||||
/**
|
||||
* Standard operator new. This function is only provided because the
|
||||
* special operator new would otherwise hide it. This function just
|
||||
* turns around and calls the global operator new function.
|
||||
*/
|
||||
void* operator new(size_t size);
|
||||
|
||||
/**
|
||||
* Placement new. This version of operator new just returns the "location"
|
||||
* parameter unchanged as its result. It ignores the "size" parameter.
|
||||
* This function is here only to allow stack allocation of UnicodeStrings
|
||||
* through the C wrapper interface. DO NOT CALL THIS FUNCTION FROM C++
|
||||
* UNLESS YOU'RE SURE YOU KNOW WHAT YOU'RE DOING!
|
||||
* @param size Ignored. There's no way this function can check the size
|
||||
* of the block you pass to it. This function trusts you've
|
||||
* allocated enough space at that location to hold a Unicode-
|
||||
* String object.
|
||||
* @param location The location where you want the new UnicodeString to
|
||||
* be stored. Typically this will be a local variable on
|
||||
* the stack. This function trusts that there's enough
|
||||
* location to hold a UnicodeString object.
|
||||
* @return Whatever was passed in for "location".
|
||||
*/
|
||||
void* operator new(size_t size, void* location);
|
||||
|
||||
UnicodeString();
|
||||
UnicodeString(const UnicodeString& that);
|
||||
UnicodeString(const UniChar* that);
|
||||
UnicodeString(const UniChar* that,
|
||||
t_int32 thatLength);
|
||||
UnicodeString(const char* that); // Must be null-terminated
|
||||
|
||||
/**
|
||||
* External-buffer constructor. This constructor allows UnicodeString to
|
||||
* use storage provided by the client as its character buffer, rather than
|
||||
* allocating its own storage. The client passes a pointer to the storage,
|
||||
* along with the number of characters currently stored in it (we don't
|
||||
* use null termination to determine the string length, and the string is
|
||||
* not ever guaranteed to be null-terminated) and the number of characters
|
||||
* the storage is capable of holding.
|
||||
* <P>
|
||||
* WARNING: Do not change the characters in the buffer during the period
|
||||
* that the UnicodeString it active. Doing so may lead to
|
||||
* undefined results.
|
||||
* <P>
|
||||
* WARNING: If the string grows beyond the capacity of the buffer passed
|
||||
* to this constructor, UnicodeString will allocate its own storage,
|
||||
* and no subsequent changes to the UnicodeString will be reflected
|
||||
* in the buffer passed to this constructor (UnicodeString itself
|
||||
* will continue to work right, however.
|
||||
* <P>
|
||||
* WARNING: The string stored in the client-owned buffer is never guaranteed
|
||||
* to be null-terminated.
|
||||
* @param charBuffer A pointer to a range of storage that the new UnicodeString
|
||||
* should use as its character-storage buffer. The client
|
||||
* retains responsibility for deleting this storage after
|
||||
* the UnicodeString goes away.
|
||||
* @param numCharsInBuffer The number of characters currently stored in charBuffer.
|
||||
* @param bufferCapabity The number of characters the buffer if capable of
|
||||
* holding. This must be greater than or equal to
|
||||
* numCharsInBuffer, but this isn't checked.
|
||||
*/
|
||||
UnicodeString(UniChar* charBuffer,
|
||||
t_int32 numCharsInBuffer,
|
||||
t_int32 bufferCapacity);
|
||||
|
||||
|
||||
/* Creates a UnicodeString from a given const char* buffer and an
|
||||
* encoding name.
|
||||
* Netscape added method.
|
||||
* <P>
|
||||
* @param that A null-terminated char buffer in a given encoding
|
||||
* @param encoding name for the encoding used for buffer
|
||||
*
|
||||
*/
|
||||
|
||||
UnicodeString(const char* that,
|
||||
const char* encoding);
|
||||
~UnicodeString() { if (!fClientOwnsStorage)
|
||||
delete [] fChars; }
|
||||
|
||||
UnicodeString& operator=(const UnicodeString& that);
|
||||
|
||||
/**
|
||||
* Compares a UnicodeString to something else. All versions of compare()
|
||||
* do bitwise comparison; internationally-sensitive comparison requires
|
||||
* the Collation library. The offset and length parameters are pinned to
|
||||
* permissible values if they are out of range.
|
||||
*/
|
||||
t_int8 compare(const UnicodeString& that) const;
|
||||
t_int8 compare(TextOffset thisOffset,
|
||||
t_int32 thisLength,
|
||||
const UnicodeString& that,
|
||||
TextOffset thatOffset,
|
||||
t_int32 thatLength) const;
|
||||
t_int8 compare(const UniChar* that) const; // Must be null-terminated
|
||||
t_int8 compare(const UniChar* that,
|
||||
t_int32 thatLength) const;
|
||||
t_int8 compare(const char* that) const;
|
||||
|
||||
/**
|
||||
* Compares substrings of two UnicodeStrings. Same as compare(), but
|
||||
* takes starting and ending offsets instead of starting offsets and
|
||||
* character counts. The characters from the starting offset up to, but
|
||||
* not including the ending offset are compared. The start and limit
|
||||
* parameters are pinned to permissible values if they are out of range.
|
||||
*/
|
||||
t_int8 compareBetween( TextOffset thisStart,
|
||||
TextOffset thisLimit,
|
||||
const UnicodeString& that,
|
||||
TextOffset thatStart,
|
||||
TextOffset thatLimit) const;
|
||||
|
||||
/**
|
||||
* Comparison operators. All of these operators map through to compare().
|
||||
*/
|
||||
t_bool operator==(const UnicodeString& that) const;
|
||||
t_bool operator!=(const UnicodeString& that) const;
|
||||
t_bool operator>(const UnicodeString& that) const;
|
||||
t_bool operator<(const UnicodeString& that) const;
|
||||
t_bool operator>=(const UnicodeString& that) const;
|
||||
t_bool operator<=(const UnicodeString& that) const;
|
||||
|
||||
/**
|
||||
* Returns the offset within this String of the first occurrence of the
|
||||
* specified substring "that". The search begins with the character at fromIndex
|
||||
* and examines at most forLength characters. Returns -1 if "that" is not found.
|
||||
*/
|
||||
TextOffset indexOf(const UnicodeString& that,
|
||||
TextOffset fromOffset = 0,
|
||||
t_uint32 forLength = -1) const;
|
||||
TextOffset indexOf(UniChar character,
|
||||
TextOffset fromOffset = 0,
|
||||
t_uint32 forLength = -1) const;
|
||||
/**
|
||||
* Returns the offset within this String of the last occurrence of the
|
||||
* specified substring "that". The search begins with the character before fromOffset
|
||||
* and examines at most forLength characters (moving backward from fromOffset).
|
||||
* Returns -1 if "that" is not found.
|
||||
*/
|
||||
TextOffset lastIndexOf(const UnicodeString& that,
|
||||
TextOffset fromOffset = T_INT32_MAX,
|
||||
t_uint32 forLength = -1) const;
|
||||
TextOffset lastIndexOf(UniChar character,
|
||||
TextOffset fromOffset = T_INT32_MAX,
|
||||
t_uint32 forLength = -1) const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if "that" appears in its entirety at the beginning of "this"
|
||||
*/
|
||||
t_bool startsWith(const UnicodeString& that) const;
|
||||
|
||||
/**
|
||||
* Returns true if "that" appears in its entirety at the end of "this"
|
||||
*/
|
||||
t_bool endsWith(const UnicodeString& that) const;
|
||||
|
||||
/**
|
||||
* Stores in "that" a copy of "this" that has had leading and trailing whitespace
|
||||
* removed from it. "this" itself is unaffected.
|
||||
*/
|
||||
UnicodeString& trim(UnicodeString& that) const;
|
||||
|
||||
/**
|
||||
* Trims leading and trailing whitespace from this UnicodeString.
|
||||
*/
|
||||
void trim();
|
||||
|
||||
/**
|
||||
* If the string is shorter than targetLength, adds enough copies of padChar to the
|
||||
* beginning to make the length targetLength and returns true; otherwise returns false.
|
||||
*/
|
||||
t_bool padLeading( t_int32 targetLength,
|
||||
UniChar padChar = ' ');
|
||||
|
||||
/**
|
||||
* If the string is shorter than targetLength, adds enough copies of padChar to the
|
||||
* end to make the length targetLength and returns true; otherwise returns false.
|
||||
*/
|
||||
t_bool padTrailing(t_int32 targetLength,
|
||||
UniChar padChar = ' ');
|
||||
|
||||
/**
|
||||
* If the string is longer than targetLength, deletes enough characters from the
|
||||
* end to make the length targetLength and returns true; otherwise returns false.
|
||||
*/
|
||||
t_bool truncate(t_int32 targetLength);
|
||||
|
||||
|
||||
/**
|
||||
* Allows UnicodeString to be used with interfaces that use UniChar*.
|
||||
* Returns a pointer to the UnicodeString's internal storage. This
|
||||
* storage is still owned by the UnicodeString, and the caller is not
|
||||
* allowed to change it. The string returned by this function is
|
||||
* correctly null-terminated.
|
||||
*/
|
||||
operator const UniChar*() const;
|
||||
|
||||
/**
|
||||
* Extracts the characters from a UnicodeString without copying. Returns
|
||||
* a pointer to the UnicodeString's internal storage. The caller
|
||||
* acquires ownership of this storage and is responsible for deleting
|
||||
* it. The UnicodeString is set to empty by this operation. WARNING: The
|
||||
* string returned is not null-terminated unless the caller explicitly
|
||||
* adds a null character to the end with operator+=().
|
||||
*/
|
||||
UniChar* orphanStorage() ;
|
||||
|
||||
/**
|
||||
* Extracts a substring. Extracts the specified substring of the
|
||||
* UnicodeString into the storage referred to by extractInto. The offset
|
||||
* and length parameters are pinned to permissible values if they are
|
||||
* out of range.
|
||||
* <P>
|
||||
* NOTE: No null byte is written to UniChar* extractInto. If you want
|
||||
* extractInto to have a null-terminated string you should do
|
||||
* extractInto[len]=0, where len is the actual number of characters
|
||||
* extracted.
|
||||
*/
|
||||
UnicodeString& extract( TextOffset thisOffset,
|
||||
t_int32 thisLength,
|
||||
UnicodeString& extractInto) const;
|
||||
void extract( TextOffset thisOffset,
|
||||
t_int32 thisLength,
|
||||
UniChar* extractInto) const;
|
||||
|
||||
/**
|
||||
* This version of extract() extracts into an array of char. The
|
||||
* characters are converted from UniChar to char by truncating the
|
||||
* high-order byte (in other words, this function assumes the Unicode
|
||||
* data being converted is all from the Latin1 character set). The
|
||||
* offset and length parameters are pinned to permissible values if they
|
||||
* are out of range.
|
||||
* <P>
|
||||
* NOTE: No null byte is written. If you want extractInto to have a
|
||||
* null-terminated string you should do extractInto[len]=0, where len is
|
||||
* the actual number of characters extracted.
|
||||
*/
|
||||
void extract( TextOffset thisOffset,
|
||||
t_int32 thisLength,
|
||||
char* extractInto) const;
|
||||
|
||||
/**
|
||||
* Extract a substring. Same as extract(), but the substring is
|
||||
* specified as starting and ending offsets [start, limit). That is,
|
||||
* from the starting offset up to, but not including, the ending offset.
|
||||
* The start and limit parameters are pinned to permissible values if
|
||||
* they are out of range.
|
||||
*/
|
||||
UnicodeString& extractBetween( TextOffset start,
|
||||
TextOffset limit,
|
||||
UnicodeString& extractInto) const;
|
||||
|
||||
/**
|
||||
* Return the character at the given offset of this string. If the
|
||||
* offset is out of range, return 0 (for the const method) or a
|
||||
* reference to a UniChar having the value 0 (for the non-const method).
|
||||
*/
|
||||
UniChar operator[](TextOffset offset) const;
|
||||
UniChar& operator[](TextOffset offset);
|
||||
|
||||
/**
|
||||
* Append a string or character. The specfied string or character is added
|
||||
* to the end of the string.
|
||||
*/
|
||||
UnicodeString& operator+=(const UnicodeString& that);
|
||||
UnicodeString& operator+=(UniChar that);
|
||||
|
||||
/**
|
||||
* Insert a string. The contents of "that" are inserted into *this so that
|
||||
* the first character from "that" occurs at thisOffset. If thisOffset is out
|
||||
* of range, the new characters are added at the end.
|
||||
*/
|
||||
UnicodeString& insert( TextOffset thisOffset,
|
||||
const UnicodeString& that);
|
||||
|
||||
/**
|
||||
* Remove part of this string. remove() with no arguments removes all
|
||||
* characters of this string. Note: The storage is not removed, but the
|
||||
* logical length, and possibly the contents, are altered.
|
||||
*/
|
||||
UnicodeString& remove();
|
||||
UnicodeString& remove( TextOffset offset,
|
||||
t_int32 length = T_INT32_MAX);
|
||||
|
||||
/**
|
||||
* Delete characters. Same as remove(), but the range of characters to
|
||||
* delete is specified as a pair of starting and ending offsets [start,
|
||||
* limit), rather than a starting offset and a character count. That is,
|
||||
* from the starting offset up to, but not including, the ending offset.
|
||||
* The start and limit parameters are pinned to permissible values if
|
||||
* they are out of range.
|
||||
*/
|
||||
UnicodeString& removeBetween( TextOffset start = 0,
|
||||
TextOffset limit = T_INT32_MAX);
|
||||
|
||||
/**
|
||||
* Replace characters. Replaces the characters in the range specified by
|
||||
* thisOffset and thisLength with the characters in "that" (or the specfied
|
||||
* subrange of "that"). All parameters are pinned to permissible values
|
||||
* if necessary. If the source and replacement text are different lengths,
|
||||
* the string will be lengthened or shortened as necessary.
|
||||
*/
|
||||
UnicodeString& replace( TextOffset thisOffset,
|
||||
t_int32 thisLength,
|
||||
const UnicodeString& that,
|
||||
TextOffset thatOffset = 0,
|
||||
t_int32 thatLength = T_INT32_MAX);
|
||||
UnicodeString& replace( TextOffset thisOfset,
|
||||
t_int32 thisLength,
|
||||
const UniChar* that);
|
||||
UnicodeString& replace( TextOffset thisOffset,
|
||||
t_int32 thisLength,
|
||||
const UniChar* that,
|
||||
t_int32 thatLength);
|
||||
|
||||
UnicodeString& replace( TextOffset thisOffset,
|
||||
t_int32 thisLength,
|
||||
const char* that);
|
||||
|
||||
/**
|
||||
* Replace characters. Same as replace(), but the affected subranges are
|
||||
* specified as pairs of starting and ending offsets [start, limit)
|
||||
* rather than starting offsets and lengths. That is, from the starting
|
||||
* offset up to, but not including, the ending offset. The start and
|
||||
* limit parameters are pinned to permissible values if they are out of
|
||||
* range.
|
||||
*/
|
||||
UnicodeString& replaceBetween( TextOffset thisStart,
|
||||
TextOffset thisLimit,
|
||||
const UnicodeString& that,
|
||||
TextOffset thatStart = 0,
|
||||
TextOffset thatLimit = T_INT32_MAX);
|
||||
|
||||
/**
|
||||
* Replaces all occurrences of "oldText" in the string in the range defined by
|
||||
* fromOffset and forLength with "newText".
|
||||
*/
|
||||
void findAndReplace( const UnicodeString& oldText,
|
||||
const UnicodeString& newText,
|
||||
TextOffset fromOffset = 0,
|
||||
t_uint32 forLength = -1);
|
||||
/**
|
||||
* Reverse the characters in this string in place. That is, "abcd"
|
||||
* becomes "dcba". Return a reference to this string.
|
||||
*/
|
||||
UnicodeString& reverse();
|
||||
UnicodeString& reverse(TextOffset from,
|
||||
TextOffset to);
|
||||
|
||||
/**
|
||||
* Convert this string to uppercase or lowercase. The methods which take
|
||||
* no arguments use the default Locale. (These methods cannot take a
|
||||
* default argument of Locale::getDefault() because that would create a
|
||||
* circular class dependency between UnicodeString and Locale.)
|
||||
*/
|
||||
UnicodeString& toUpper();
|
||||
UnicodeString& toUpper(const Locale& locale);
|
||||
UnicodeString& toLower();
|
||||
UnicodeString& toLower(const Locale& locale);
|
||||
|
||||
/**
|
||||
* Return the length of this string. This will always be a non-negative
|
||||
* number.
|
||||
*/
|
||||
t_int32 size() const;
|
||||
|
||||
/**
|
||||
* Return the hash code for this string. This is used by hash tables
|
||||
* which use this object as a key. The hash code is cached, and
|
||||
* recomputed when necessary. For this reason, this method may alter the
|
||||
* physical object, even though it is semantically const.
|
||||
*/
|
||||
t_int32 hashCode() const;
|
||||
|
||||
/**
|
||||
* Returns the number of display cells the specified substring takes up.
|
||||
* This function is designed for Asian text and properly takes into account
|
||||
* halfwidth and fullwidth variants of various CJK characters and the combining
|
||||
* behavior of the Hangul Jamo characters (with some limitations; see
|
||||
* documentation for Unicode::getCellWidth()).
|
||||
* <P>
|
||||
* In order to avoid dealing
|
||||
* with fractions, this function can either be construed to return twice the
|
||||
* actual number of display cells or to treat a "cell" as the width of a halfwidth
|
||||
* character rather than the width of a fullwidth character.
|
||||
* <P>
|
||||
* The "asian" parameter controls whether characters considered NEUTRAL by
|
||||
* the Unicode class are treated as halfwidth or fullwidth here. If you set
|
||||
* "asian" to FALSE, neutrals are treated as halfwidth, and this function returns
|
||||
* a close approximation of how many Latin display cells the text will take up
|
||||
* in a monospaced font.
|
||||
*/
|
||||
t_int32 numDisplayCells(TextOffset fromOffset = 0,
|
||||
t_int32 forLength = T_INT32_MAX,
|
||||
t_bool asian = TRUE) const;
|
||||
/**
|
||||
* The streamIn and streamOut methods read and write objects of this
|
||||
* class as binary, platform-dependent data in the iostream. The stream
|
||||
* must be in ios::binary mode for this to work. These methods are not
|
||||
* intended for general public use; they are used by the framework to
|
||||
* improve performance by storing certain objects in binary files.
|
||||
*/
|
||||
void streamOut(FILE* os) const;
|
||||
void streamIn(FILE* is);
|
||||
|
||||
/**
|
||||
* Returns TRUE if the string resize failed. It is very important
|
||||
* to check if a unicode string is valid after modification.
|
||||
*/
|
||||
t_bool isBogus() const;
|
||||
|
||||
/*
|
||||
* Additional Netscape routines
|
||||
*/
|
||||
/** Converts the String to a char* using a target encoding */
|
||||
char* toCString(const char* encoding) const;
|
||||
|
||||
/** Compare case insensitive. Still diacrit sensitive. Is not locale sensitive.
|
||||
* All versions of compare() do bitwise comparison; internationally-
|
||||
* sensitive comparison requires the Collation library. */
|
||||
int compareIgnoreCase(const UnicodeString& that) const;
|
||||
int compareIgnoreCase(const UniChar* that,
|
||||
t_int32 thatLength) const;
|
||||
int compareIgnoreCase(const UniChar* that) const;
|
||||
int compareIgnoreCase(const char* that,
|
||||
const char* encoding) const;
|
||||
/* Assumes a LATIN-1 string */
|
||||
int
|
||||
compareIgnoreCase(const char* that) const;
|
||||
|
||||
|
||||
private:
|
||||
/* Netscape Private */
|
||||
char* toCStringTruncate() const;
|
||||
|
||||
static t_int32 lengthOf(const UniChar* chars);
|
||||
static t_int32 lengthOf(const char* chars);
|
||||
void resize(t_int32 newLength);
|
||||
void setToBogus(void);
|
||||
static void copy( const UniChar* from,
|
||||
UniChar* to,
|
||||
t_int32 numChars);
|
||||
static void copy( const char* from,
|
||||
UniChar* to,
|
||||
t_int32 numChars);
|
||||
static void copy( const UniChar* from,
|
||||
char* to,
|
||||
t_int32 numChars);
|
||||
|
||||
t_int8 doCompare( const UniChar* thiss,
|
||||
t_int32 thisLength,
|
||||
const UniChar* that,
|
||||
t_int32 thatLength) const;
|
||||
static const t_int32 kInvalidHashCode;
|
||||
static const t_int32 kEmptyHashCode;
|
||||
static UniChar fgErrorChar;
|
||||
|
||||
UniChar* fChars;
|
||||
t_int32 fSize;
|
||||
t_int32 fCapacity;
|
||||
t_int32 fHashCode;
|
||||
t_bool fClientOwnsStorage;
|
||||
t_bool fBogus;
|
||||
};
|
||||
|
||||
#ifdef NLS_MAC
|
||||
#pragma export off
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Write the contents of a UnicodeString to an ostream. This functions writes
|
||||
* the characters in a UnicodeString to an ostream. The UniChars in the
|
||||
* UnicodeString are truncated to char, leading to undefined results with
|
||||
* anything not in the Latin1 character set.
|
||||
*/
|
||||
NLSUNIAPI_PUBLIC(ostream&) operator<<(ostream& stream,
|
||||
const UnicodeString& string);
|
||||
|
||||
//----------------------------------------------------
|
||||
// operator new
|
||||
//----------------------------------------------------
|
||||
|
||||
inline void*
|
||||
UnicodeString::operator new(size_t size)
|
||||
{
|
||||
return ::operator new(size);
|
||||
}
|
||||
|
||||
inline void*
|
||||
UnicodeString::operator new(size_t size, void* location)
|
||||
{
|
||||
// WARNING: Do not use this operator unless you're sure you know what you're
|
||||
// doing! It just passes "location" through blindly. If there isn't enough
|
||||
// free space at "location" to hold a UnicodeString (or if "location" is
|
||||
// somehow invalid), you're in trouble!
|
||||
return location;
|
||||
}
|
||||
//----------------------------------------------------
|
||||
// Fast append
|
||||
//----------------------------------------------------
|
||||
|
||||
inline UnicodeString&
|
||||
UnicodeString::operator+=(UniChar that)
|
||||
{
|
||||
if (fSize < fCapacity) {
|
||||
fChars[fSize++] = that;
|
||||
fHashCode = kInvalidHashCode;
|
||||
} else {
|
||||
resize(fSize + 1);
|
||||
if (!fBogus) // change required for HP-UX
|
||||
fChars[fSize - 1] = that;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//----------------------------------------------------
|
||||
// Character access
|
||||
//----------------------------------------------------
|
||||
|
||||
inline UniChar
|
||||
UnicodeString::operator[](TextOffset offset) const
|
||||
{
|
||||
// Cast to unsigned in order to detect negative values.
|
||||
// Assume fSize >= 0.
|
||||
return ((t_uint32)offset < (t_uint32)fSize) ? fChars[offset] : 0;
|
||||
}
|
||||
|
||||
inline UniChar&
|
||||
UnicodeString::operator[](TextOffset offset)
|
||||
{
|
||||
// Cast to unsigned in order to detect negative values
|
||||
// Assume fSize >= 0.
|
||||
|
||||
UniChar& result = fgErrorChar;
|
||||
if ((t_uint32)offset < (t_uint32)fSize)
|
||||
{
|
||||
fHashCode = kInvalidHashCode;
|
||||
result = fChars[offset];
|
||||
} else
|
||||
{
|
||||
fgErrorChar = 0; // Always reset this to zero in case the caller has modified it
|
||||
result = fgErrorChar;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------
|
||||
// Other inline methods
|
||||
//----------------------------------------------------
|
||||
|
||||
inline UnicodeString&
|
||||
UnicodeString::remove()
|
||||
{
|
||||
fSize = 0;
|
||||
fBogus = FALSE;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline t_int32
|
||||
UnicodeString::size() const
|
||||
{
|
||||
return fSize;
|
||||
}
|
||||
|
||||
inline t_int8
|
||||
UnicodeString::compare(const UnicodeString& that) const
|
||||
{
|
||||
return doCompare(fChars, fSize, that.fChars, that.fSize);
|
||||
}
|
||||
|
||||
inline t_bool
|
||||
UnicodeString::operator==(const UnicodeString& that) const
|
||||
{
|
||||
// Check fSize first to avoid the call to compare in many cases
|
||||
return fSize == that.fSize && compare(that) == 0;
|
||||
}
|
||||
|
||||
|
||||
inline t_bool
|
||||
UnicodeString::operator!=(const UnicodeString& that) const
|
||||
{
|
||||
return compare(that) != 0;
|
||||
}
|
||||
|
||||
inline t_bool
|
||||
UnicodeString::operator>(const UnicodeString& that) const
|
||||
{
|
||||
return compare(that) == 1;
|
||||
}
|
||||
|
||||
inline t_bool
|
||||
UnicodeString::operator<(const UnicodeString& that) const
|
||||
{
|
||||
return compare(that) == -1;
|
||||
}
|
||||
|
||||
inline t_bool
|
||||
UnicodeString::operator<=(const UnicodeString& that) const
|
||||
{
|
||||
return compare(that) != 1;
|
||||
}
|
||||
|
||||
inline t_bool
|
||||
UnicodeString::operator>=(const UnicodeString& that) const
|
||||
{
|
||||
return compare(that) != -1;
|
||||
}
|
||||
|
||||
inline t_bool
|
||||
UnicodeString::isBogus() const { return fBogus; }
|
||||
|
||||
/**
|
||||
* The arrayCopy() methods copy an array of UnicodeString OBJECTS (not
|
||||
* pointers).
|
||||
*/
|
||||
inline void arrayCopy(const UnicodeString* src, UnicodeString* dst, t_int32 count)
|
||||
{ while (count-- > 0) *dst++ = *src++; }
|
||||
|
||||
inline void arrayCopy(const UnicodeString* src, t_int32 srcStart, UnicodeString* dst, t_int32 dstStart, t_int32 count)
|
||||
{ arrayCopy(src+srcStart, dst+dstStart, count); }
|
||||
|
||||
#endif
|
Загрузка…
Ссылка в новой задаче