LibreOffice: XCharacterClassification Interface Reference

LibreOffice LibreOffice 7.3 SDK API Reference

Loading...
Searching...
No Matches
Public Member Functions | List of all members
XCharacterClassification Interface Referencepublished

Character classification (upper, lower, digit, letter, number, ...) and generic Unicode enabled parser. More...

Inheritance diagram for XCharacterClassification:

## Public Member Functions
string | toUpper ([in] string aText, [in] long nPos, [in] long nCount, [in] com::sun::star::lang::Locale aLocale)
| Convert lower case alpha to upper case alpha, starting at position nPos for nCount code points.
string | toLower ([in] string aText, [in] long nPos, [in] long nCount, [in] com::sun::star::lang::Locale aLocale)
| Convert upper case alpha to lower case alpha, starting at position nPos for nCount code points.
string | toTitle ([in] string aText, [in] long nPos, [in] long nCount, [in] com::sun::star::lang::Locale aLocale)
| Convert to title case, starting at position nPos for nCount code points.
short | getType ([in] string aText, [in] long nPos)
| Get UnicodeType of character at position nPos.
short | getCharacterDirection ([in] string aText, [in] long nPos)
| Get DirectionProperty of character at position nPos.
short | getScript ([in] string aText, [in] long nPos)
| Get UnicodeScript of character at position nPos.
long | getCharacterType ([in] string aText, [in] long nPos, [in] com::sun::star::lang::Locale aLocale)
| Get KCharacterType of character at position nPos.
long | getStringType ([in] string aText, [in] long nPos, [in] long nCount, [in] com::sun::star::lang::Locale aLocale)
| Get accumulated KCharacterTypes of string starting at position nPos of length nCount code points.
ParseResult | parseAnyToken ([in] string aText, [in] long nPos, [in] com::sun::star::lang::Locale aLocale, [in] long nStartCharFlags, [in] string aUserDefinedCharactersStart, [in] long nContCharFlags, [in] string aUserDefinedCharactersCont)
| Parse a string for a token starting at position nPos.
ParseResult | parsePredefinedToken ([in] long nTokenType, [in] string aText, [in] long nPos, [in] com::sun::star::lang::Locale aLocale, [in] long nStartCharFlags, [in] string aUserDefinedCharactersStart, [in] long nContCharFlags, [in] string aUserDefinedCharactersCont)
| Parse a string for a token of type nTokenType starting at position nPos.
Public Member Functions inherited from XInterface
any | queryInterface ([in] type aType)
| queries for a new interface to an existing UNO object.
void | acquire ()
| increases the reference counter by one.
void | release ()
| decreases the reference counter by one.

## Detailed Description

Character classification (upper, lower, digit, letter, number, ...) and generic Unicode enabled parser.

Developers Guide
  OfficeDev - Implementing a New Locale - XCharacterClassification
  OfficeDev - Overview and Using the API - XCharacterClassification

## Member Function Documentation

## ◆ getCharacterDirection()

short getCharacterDirection | ( | [in] string | aText,
|  | [in] long | nPos
| ) |  |

Get DirectionProperty of character at position nPos.

## ◆ getCharacterType()

long getCharacterType | ( | [in] string | aText,
|  | [in] long | nPos,
|  | [in] com::sun::star::lang::Locale | aLocale
| ) |  |

Get KCharacterType of character at position nPos.

## ◆ getScript()

short getScript | ( | [in] string | aText,
|  | [in] long | nPos
| ) |  |

Get UnicodeScript of character at position nPos.

## ◆ getStringType()

long getStringType | ( | [in] string | aText,
|  | [in] long | nPos,
|  | [in] long | nCount,
|  | [in] com::sun::star::lang::Locale | aLocale
| ) |  |

Get accumulated KCharacterTypes of string starting at position nPos of length nCount code points.

Returns
  A number with appropriate flags set to indicate what type of characters the string contains, each flag value being one of KCharacterType values.

## ◆ getType()

short getType | ( | [in] string | aText,
|  | [in] long | nPos
| ) |  |

Get UnicodeType of character at position nPos.

## ◆ parseAnyToken()

ParseResult parseAnyToken | ( | [in] string | aText,
|  | [in] long | nPos,
|  | [in] com::sun::star::lang::Locale | aLocale,
|  | [in] long | nStartCharFlags,
|  | [in] string | aUserDefinedCharactersStart,
|  | [in] long | nContCharFlags,
|  | [in] string | aUserDefinedCharactersCont
| ) |  |

Parse a string for a token starting at position nPos.

A name or identifier must match the KParseTokens criteria passed in nStartCharFlags and nContCharFlags and may additionally contain characters of aUserDefinedCharactersStart and/or aUserDefinedCharactersCont.

Returns
  A filled ParseResult structure. If no unambiguous token could be parsed, ParseResult::TokenType will be set to 0 (zero), other fields will contain the values parsed so far.

If a token may represent either a numeric value or a name according to the passed Start/Cont-Flags/Chars, both KParseType::ASC_NUM (or KParseType::UNI_NUM) and KParseType::IDENTNAME are set in ParseResult::TokenType.

Parameters

  aText | Text to be parsed.
  nPos | Position where parsing starts.
  aLocale | The locale, for example, for decimal and group separator or character type determination.
  nStartCharFlags | A set of KParseTokens constants determining the allowed characters a name or identifier may start with.
  aUserDefinedCharactersStart | A set of additionally allowed characters a name or identifier may start with.
  nContCharFlags | A set of KParseTokens constants determining the allowed characters a name or identifier may continue with.
  aUserDefinedCharactersCont | A set of additionally allowed characters a name or identifier may continue with.

using namespace ::com::sun::star::i18n;
// First character of an identifier may be any alphabetic or underscore.
sal_Int32 nStartFlags = KParseTokens::ANY_ALPHA | KParseTokens::ASC_UNDERSCORE;
// Continuing characters may be any alphanumeric or underscore or dot.
sal_Int32 nContFlags = KParseTokens::ANY_ALNUM | KParseTokens::ASC_UNDERSCORE | KParseTokens::ASC_DOT;
// No further characters assumed to be contained in an identifier
OUString aEmptyString;
// Parse any token.
ParseResult rRes = xCC->parseAnyToken( aText, nPos, aLocale,
nStartFlags, aEmptyString, nContFlags, aEmptyString );
// Get parsed token.
if ( rRes.TokenType & (KParseType::ASC_NUMBER | KParseType::UNI_NUMBER) )
fValue = rRes.Value;
if ( rRes.TokenType & KParseType::IDENTNAME )
aName = aText.copy( nPos, rRes.EndPos - nPos );
else if ( rRes.TokenType & KParseType::SINGLE_QUOTE_NAME )
aName = rRes.DequotedNameOrString;
else if ( rRes.TokenType & KParseType::DOUBLE_QUOTE_STRING )
aString = rRes.DequotedNameOrString;
else if ( rRes.TokenType & KParseType::BOOLEAN )
aSymbol = aText.copy( nPos, rRes.EndPos - nPos );
else if ( rRes.TokenType & KParseType::ONE_SINGLE_CHAR )
aSymbol = aText.copy( nPos, rRes.EndPos - nPos );
com::sun::star::i18n::KParseTokens::ASC_DOT
const long ASC_DOT
ASCII '.' dot/point.
Definition: KParseTokens.idl:55
com::sun::star::i18n::KParseTokens::ANY_ALNUM
const long ANY_ALNUM
any (ASCII or Unicode) alphanumeric
Definition: KParseTokens.idl:175
com::sun::star::i18n::KParseTokens::ASC_UNDERSCORE
const long ASC_UNDERSCORE
ASCII '_' underscore.
Definition: KParseTokens.idl:49
com::sun::star::i18n::KParseTokens::ANY_ALPHA
const long ANY_ALPHA
any (ASCII or Unicode) alpha
Definition: KParseTokens.idl:169
com::sun::star::i18n::KParseType::SINGLE_QUOTE_NAME
const long SINGLE_QUOTE_NAME
"A single-quoted name matching the conditions passed ( 'na\'me' )." "Dequoted name in ParseResult::De...
Definition: KParseType.idl:53
com::sun::star::i18n::KParseType::ASC_NUMBER
const long ASC_NUMBER
A number where all digits are ASCII characters.
Definition: KParseType.idl:61
com::sun::star::i18n::KParseType::ONE_SINGLE_CHAR
const long ONE_SINGLE_CHAR
One single character like ! # ; : $ et al.
Definition: KParseType.idl:38
com::sun::star::i18n::KParseType::BOOLEAN
const long BOOLEAN
A Boolean operator like <, >, <>, =, <=, >=.
Definition: KParseType.idl:42
com::sun::star::i18n::KParseType::DOUBLE_QUOTE_STRING
const long DOUBLE_QUOTE_STRING
A double-quoted string ( "str\"i""ng" ).
Definition: KParseType.idl:57
com::sun::star::i18n::KParseType::UNI_NUMBER
const long UNI_NUMBER
A number where at least some digits are Unicode (and maybe ASCII) characters.
Definition: KParseType.idl:66
com::sun::star::i18n::KParseType::IDENTNAME
const long IDENTNAME
A name matching the conditions passed.
Definition: KParseType.idl:45
com::sun::star::i18n
Interface for internationalization.
Definition: AmPmValue.idl:24
com::sun::star::i18n::ParseResult
Parser results returned by XCharacterClassification::parseAnyToken() and XCharacterClassification::pa...
Definition: ParseResult.idl:33
com::sun::star::i18n::ParseResult::TokenType
long TokenType
KParseType token type like KParseType::IDENTNAME.
Definition: ParseResult.idl:50
com::sun::star::i18n::ParseResult::Value
double Value
Value of token in case of numeric.
Definition: ParseResult.idl:46
com::sun::star::i18n::ParseResult::DequotedNameOrString
string DequotedNameOrString
If a quoted name or string is encountered the dequoted result goes here.
Definition: ParseResult.idl:66
com::sun::star::i18n::ParseResult::EndPos
long EndPos
UTF-16 code unit index of first unprocessed character.
Definition: ParseResult.idl:39

## ◆ parsePredefinedToken()

ParseResult parsePredefinedToken | ( | [in] long | nTokenType,
|  | [in] string | aText,
|  | [in] long | nPos,
|  | [in] com::sun::star::lang::Locale | aLocale,
|  | [in] long | nStartCharFlags,
|  | [in] string | aUserDefinedCharactersStart,
|  | [in] long | nContCharFlags,
|  | [in] string | aUserDefinedCharactersCont
| ) |  |

Parse a string for a token of type nTokenType starting at position nPos.

Other parameters are the same as in parseAnyToken(). If the actual token does not match the passed nTokenType a ParseResult::TokenType set to 0 (zero) is returned.

Parameters

  nTokenType | One or more of the KParseType constants.
  aText | See parseAnyToken
  nPos | See parseAnyToken
  aLocale | See parseAnyToken
  nStartCharFlags | See parseAnyToken
  aUserDefinedCharactersStart | See parseAnyToken
  nContCharFlags | See parseAnyToken
  aUserDefinedCharactersCont | See parseAnyToken

// Determine if a given name is a valid name (not quoted) and contains
// only allowed characters.
using namespace ::com::sun::star::i18n;
// First character of an identifier may be any alphanumeric or underscore.
sal_Int32 nStartFlags = KParseTokens::ANY_ALNUM | KParseTokens::ASC_UNDERSCORE;
// No further characters assumed to be contained in an identifier start.
OUString aEmptyString;
// Continuing characters may be any alphanumeric or underscore.
sal_Int32 nContFlags = nStartFlags;
// Additionally, continuing characters may contain a blank.
OUString aContChars( " " );
// Parse predefined (must be an IDENTNAME) token.
ParseResult rRes = xCC->parsePredefinedToken( KParseType::IDENTNAME, rName, 0, aLocale,
nStartFlags, aEmptyString, nContFlags, aContChars );
// Test if it is an identifier name and if it only is one
// and no more else is following it.
bValid = (rRes.TokenType & KParseType::IDENTNAME) && rRes.EndPos == rName.Len();

## ◆ toLower()

string toLower | ( | [in] string | aText,
|  | [in] long | nPos,
|  | [in] long | nCount,
|  | [in] com::sun::star::lang::Locale | aLocale
| ) |  |

Convert upper case alpha to lower case alpha, starting at position nPos for nCount code points.

## ◆ toTitle()

string toTitle | ( | [in] string | aText,
|  | [in] long | nPos,
|  | [in] long | nCount,
|  | [in] com::sun::star::lang::Locale | aLocale
| ) |  |

Convert to title case, starting at position nPos for nCount code points.

## ◆ toUpper()

string toUpper | ( | [in] string | aText,
|  | [in] long | nPos,
|  | [in] long | nCount,
|  | [in] com::sun::star::lang::Locale | aLocale
| ) |  |

Convert lower case alpha to upper case alpha, starting at position nPos for nCount code points.

The documentation for this interface was generated from the following file:

- com/sun/star/i18n/XCharacterClassification.idl