LIBULS.LIB
LIBULS.LIB is the import library for the OS/2 Unicode Locale Services (ULS), distributed with the IBM OS/2 Developer's Toolkit. It provides the linker stubs for a comprehensive Unicode-aware API covering locale objects, character classification, string manipulation, collation, case conversion, date/time/number formatting, and string transforms. The ULS is IBM's system-level Unicode infrastructure for OS/2 national language support.
File size in the OS/2 Warp 4.52 Toolkit 4.5: 7,680 bytes (2001-10-02). Source DLL: LIBUNI.DLL.
Overview
The ULS API models Unicode locale handling through three central object types:
| Type | Handle | Role |
|---|---|---|
| Locale object | LocaleObject |
Encapsulates all locale-specific rules: collation, number format, date/time format, currency, text separators. Analogous to POSIX locale_t.
|
| Attr object | AttrObject |
A compiled character attribute table for fast per-character classification queries. Created from a locale object. |
| Transform object | TransformObject |
A compiled rule set for string transformation (case folding, normalization, transliteration). |
The fundamental character type throughout the ULS API is UniChar (a 16-bit unsigned value, UTF-16LE code unit), and most string functions operate on null-terminated arrays of UniChar.
API Summary
LIBULS.LIB exports 93 symbols grouped into eight functional areas:
| Group | Functions | Description |
|---|---|---|
| Locale objects | 7 | Create, free, query locale handles |
| Locale information | 9 | Query locale items, values, lists, country/language names |
| User locale | 7 | Create, modify, save user-customized locales |
| Attr objects | 4 | Compile attribute tables, scan for character attributes |
| Character classification | 14 | Unicode equivalents of <ctype.h> predicates
|
| Unicode strings | 24 | Locale-aware equivalents of C runtime string functions |
| Formatting | 3 | Date/time, monetary, and numeric string formatting |
| Transform objects | 8 | Case conversion, string transforms, collation keys |
Locale Objects
UniCreateLocaleObject(ulLocType, cpszLocale, pLocaleObj)- Creates a locale object from the locale specification
cpszLocale.ulLocTypeselects the format:UNI_MBS_STRING_POINTER— locale name as a multibyte string (e.g."en_US","ja_JP")UNI_UCS_STRING_POINTER— locale name as aUniCharstringUNI_TOKEN_POINTER— locale as a locale token
- Returns
ULS_SUCCESSand stores the handle in*pLocaleObj.
UniFreeLocaleObject(localeObj)- Releases all memory associated with a locale object.
UniQueryLocaleObject(localeObj, ulCategory, ulType, ppvInfo)- Returns a pointer to a specific information block within the locale object.
ulCategoryselectsLC_CTYPE,LC_COLLATE,LC_TIME,LC_NUMERIC,LC_MONETARY, orLC_MESSAGES.ulTyperefines the requested data.
UniLocaleStrToToken(ulType, cpszLocale, pLocToken)- Converts a locale name string to a compact locale token.
UniLocaleTokenToStr(locToken, ulType, ppszLocale)- Converts a locale token back to a locale name string.
UniQueryLocaleList(ulFlags, puniStr, ulBufLen)- Enumerates available locale names into a buffer.
ulFlagscontrols whether system locales, user-defined locales, or both are included.
UniMapCtryToLocale(usCtry, usCP, puniLocale, ulBufLen)- Maps an OS/2 country code and codepage pair to a ULS locale name string. Used to bridge the older OS/2 NLS country-code model to ULS locale objects.
Locale Information
UniQueryLocaleInfo(localeObj, ppLocaleInfo)- Returns a
LOCALEINFOITEMSstructure with pointers to the locale's format strings, separators, and symbols: decimal separator, thousands separator, currency symbol, date/time format strings, AM/PM strings, day and month names, collation name, etc.
UniFreeLocaleInfo(pLocaleInfo)- Releases a
LOCALEINFOITEMSstructure returned byUniQueryLocaleInfo.
UniQueryLocaleItem(localeObj, ulItem, ppuniStr)- Retrieves a single locale string item by item ID. Item IDs are
LOCI_*constants:LOCI_sDecimal— decimal separator characterLOCI_sThousand— thousands grouping separatorLOCI_sCurrency— currency symbolLOCI_sDate— date separatorLOCI_sTime— time separatorLOCI_sAM/LOCI_sPM— AM/PM stringsLOCI_sShortDate— short date format patternLOCI_sLongDate— long date format patternLOCI_s1159— morning designatorLOCI_s2359— evening designatorLOCI_sLanguage— language abbreviationLOCI_sCountry— country abbreviation
UniQueryLocaleValue(localeObj, ulItem, pulValue)- Retrieves a single numeric locale value by item ID. Numeric items include:
LOCI_iDate— date format order (0=MDY, 1=DMY, 2=YMD)LOCI_iTime— time format (0=12h, 1=24h)LOCI_iCurrency— currency position (0=prefix, 1=suffix, 2=prefix with space, 3=suffix with space)LOCI_iDigits— decimal digits after decimal pointLOCI_iNegNumber— negative number format style
UniQueryCountryName(localeObj, ulType, ppuniStr)- Returns the country name in the locale's language.
UniQueryLanguageName(localeObj, ulType, ppuniStr)- Returns the language name in the locale's language.
UniQueryNumericValue(localeObj, ulItem, pdblValue)- Returns a locale numeric attribute as a double.
User Locale
OS/2 users can customize locale settings. The user locale functions create and manage these customizations.
UniMakeUserLocale(cpszLocaleName, cpszBaseName, pUserLocObj)- Creates a user locale object named
cpszLocaleNamebased on existing localecpszBaseName. Returns the new locale object handle.
UniCreateUserLocale(cpszLocaleName, pUserLocObj)- Creates a new empty user locale.
UniDeleteUserLocale(cpszLocaleName)- Permanently deletes a user-defined locale from the system.
UniCompleteUserLocale(userLocObj)- Finalizes a user locale after all item modifications have been made, building the internal data tables.
UniSetUserLocaleItem(userLocObj, ulItem, ulType, pValue)- Sets one item in a user locale object (a string or numeric value by
LOCI_*item ID).
UniGetOverride(localeObj, ulItem, ppuniStr)- Returns the user-defined override value for a locale item, or NULL if the item uses the system default.
Attr Objects
Attr objects are pre-compiled character attribute tables that allow fast classification of individual Unicode characters without consulting the full locale object on each call.
UniCreateAttrObject(localeObj, puniAttrName, pAttrObj)- Compiles a character attribute table from the locale object for attribute class
puniAttrName(e.g.L"upper",L"lower",L"alpha",L"digit"). Returns anAttrObjecthandle.
UniFreeAttrObject(attrObj)- Frees an attr object.
UniQueryAttr(attrObj, uc)- Returns TRUE if Unicode character
uchas the attribute encoded inattrObj. Faster than callingUniQueryAlphaetc. for repeated queries in a loop.
UniScanForAttr(attrObj, puniStr, ulLen, fNotAttr, pulOffset)- Scans
puniStr(up toulLencharacters) looking for the first character that has (or does not have, iffNotAttris TRUE) the attribute inattrObj. Returns the offset in*pulOffset.
Character Classification
These functions test a single UniChar against a locale's classification rules. They are locale-aware equivalents of the C standard <ctype.h> predicates.
| ULS function | C runtime equivalent | True when |
|---|---|---|
UniQueryAlpha(locObj, uc) |
isalpha(c) |
Letter (any script) |
UniQueryDigit(locObj, uc) |
isdigit(c) |
Decimal digit |
UniQueryAlnum(locObj, uc) |
isalnum(c) |
Letter or decimal digit |
UniQueryLower(locObj, uc) |
islower(c) |
Lowercase letter |
UniQueryUpper(locObj, uc) |
isupper(c) |
Uppercase letter |
UniQueryPunct(locObj, uc) |
ispunct(c) |
Punctuation character |
UniQuerySpace(locObj, uc) |
isspace(c) |
Whitespace (space, tab, newline, etc.) |
UniQueryBlank(locObj, uc) |
isblank(c) |
Space or horizontal tab only |
UniQueryCntrl(locObj, uc) |
iscntrl(c) |
Control character (C0/C1) |
UniQueryPrint(locObj, uc) |
isprint(c) |
Printable (including space) |
UniQueryGraph(locObj, uc) |
isgraph(c) |
Printable and visible (excluding space) |
UniQueryXdigit(locObj, uc) |
isxdigit(c) |
Hexadecimal digit [0–9 A–F a–f] |
Additional character attribute queries:
UniQueryChar(locObj, uc, ulAttr)- General character attribute test.
ulAttris aCT_*attribute constant (e.g.CT_UPPER,CT_LOWER,CT_DIGIT,CT_SPACE,CT_PUNCT,CT_CNTRL,CT_BLANK,CT_XDIGIT,CT_ALPHA).
UniQueryCharAttr(locObj, uc, pulAttr)- Returns the complete character attribute bitmask for
ucin*pulAttr. The bitmask is a combination ofCT_*flags.
UniQueryCharType(locObj, uc, pulType)- Returns the Unicode general category of
uc(e.g. uppercase letter, lowercase letter, decimal digit, currency symbol, etc.) as aUCT_*value.
UniQueryCharTypeTable(locObj, ppTable, pulSize)- Returns a pointer to the locale's internal character type table. Used for bulk classification without per-character function call overhead.
UniQueryStringType(locObj, puniStr, ulLen, pulTypes)- Classifies each character in
puniStrand fillspulTypes[]with the correspondingCT_*bitmasks. More efficient than callingUniQueryCharAttrin a loop.
Unicode String Operations
The UniStr* functions are locale-aware Unicode equivalents of the C runtime string library. They operate on null-terminated UniChar (UTF-16LE) strings.
Copying and concatenation
UniStrcpy(puniDst, puniSrc)- Copies null-terminated Unicode string
puniSrctopuniDst. ReturnspuniDst.
UniStrncpy(puniDst, puniSrc, n)- Copies at most
ncharacters.
UniStrcat(puniDst, puniSrc)- Appends
puniSrctopuniDst.
UniStrncat(puniDst, puniSrc, n)- Appends at most
ncharacters.
Length and search
UniStrlen(puniStr)- Returns the number of
UniCharunits in the string (not bytes), excluding the null terminator.
UniStrchr(puniStr, uc)- Returns a pointer to the first occurrence of
UniCharucinpuniStr, or NULL.
UniStrrchr(puniStr, uc)- Returns a pointer to the last occurrence.
UniStrstr(puniStr, puniSub)- Returns a pointer to the first occurrence of substring
puniSubinpuniStr.
UniStrcspn(puniStr, puniReject)- Returns the length of the initial segment of
puniStrthat contains no characters frompuniReject.
UniStrspn(puniStr, puniAccept)- Returns the length of the initial segment containing only characters from
puniAccept.
UniStrpbrk(puniStr, puniAccept)- Returns a pointer to the first character in
puniStrthat also appears inpuniAccept.
UniStrtok(puniStr, puniDelim)- Tokenizes a string — locale-aware equivalent of
strtok. Pass NULL forpuniStron subsequent calls.
Comparison and collation
UniStrcmp(puniStr1, puniStr2)- Code-point comparison (binary). Returns negative, zero, or positive.
UniStrncmp(puniStr1, puniStr2, n)- Code-point comparison of at most
ncharacters.
UniStrcmpi(locObj, puniStr1, puniStr2)- Case-insensitive code-point comparison.
UniStrncmpi(locObj, puniStr1, puniStr2, n)- Case-insensitive comparison of at most
ncharacters.
UniStrcoll(locObj, puniStr1, puniStr2)- Locale-aware collation comparison. Uses the locale's sort rules (handles accents, locale-specific ordering like Spanish "ll" as a digraph). Equivalent to POSIX
strcoll.
UniStrxfrm(locObj, puniDst, puniSrc, n)- Transforms
puniSrcinto a sort key string such that a simpleUniStrcmpon two transformed strings gives the same result asUniStrcollon the originals. Equivalent to POSIXstrxfrm. Use when comparing the same string against many others.
Case conversion
UniStrlwr(locObj, puniStr)- Converts
puniStrto lowercase in-place using locale rules. ReturnspuniStr.
UniStrupr(locObj, puniStr)- Converts
puniStrto uppercase in-place.
Numeric parsing
UniStrtod(locObj, puniStr, ppuniEnd)- Parses a floating-point number from
puniStrusing the locale's decimal separator. Returns adouble. Sets*ppuniEndto the first character not consumed.
UniStrtol(locObj, puniStr, ppuniEnd, iBase)- Parses a signed long integer from
puniStr.
UniStrtoul(locObj, puniStr, ppuniEnd, iBase)- Parses an unsigned long integer.
String Formatting
UniStrftime(locObj, puniDst, n, puniFormat, ptm)- Formats a
struct tmdate/time intopuniDst(aUniCharbuffer of at mostncharacters) using the format stringpuniFormat. Format codes are the same as ANSIstrftime(%Y,%m,%d,%H,%M,%S,%A,%B, etc.) but the output uses locale-specific day names, month names, AM/PM strings, and date/time separators.
UniStrptime(locObj, puniStr, puniFormat, ptm)- Parses a date/time string according to the locale's format and fills a
struct tm. Locale-aware inverse ofUniStrftime.
UniStrfmon(locObj, puniDst, n, puniFormat, ...)- Formats monetary values into
puniDstusing the locale's currency symbol, decimal separator, and grouping rules. Locale-aware equivalent of POSIXstrfmon. Format codes include%n(national format) and%i(international format).
Transform Objects and Case Conversion
UniCreateTransformObject(locObj, puniTransName, pTransObj)- Compiles a named transformation rule set from the locale.
puniTransNameidentifies the transform (e.g.L"upper",L"lower",L"fold"for case folding,L"compose"for canonical composition). Returns aTransformObjecthandle.
UniFreeTransformObject(transObj)- Frees a transform object.
UniTransformStr(transObj, puniSrc, pulSrcLen, puniDst, pulDstLen)- Applies the transformation in
transObjtopuniSrc(up to*pulSrcLencharacters) and writes the result topuniDst. Updates*pulSrcLenand*pulDstLento the number of characters consumed and produced.
UniTolower(locObj, uc)- Converts a single
UniCharto lowercase. Returns the lowercase equivalent, orucunchanged if it has no lowercase form.
UniToupper(locObj, uc)- Converts a single
UniCharto uppercase.
UniTransLower(locObj, puniStr)- Converts an entire
UniCharstring to lowercase in-place using locale case rules.
UniTransUpper(locObj, puniStr)- Converts an entire
UniCharstring to uppercase in-place.
Collation keys
UniMakeKey(locObj, puniStr, pKey, ulKeyBufLen)- Computes a locale-aware sort key for
puniStrand stores it inpKey. Sort keys are opaque byte sequences that can be compared withmemcmpto give locale-correct ordering, equivalent to the output ofUniStrxfrm.
UniGetColval(locObj, uc, pulColval)- Returns the primary collation weight for a single character.
Codepage conversion
UniProcessUconv(uconvObj, ppInBuf, pulInLen, ppOutBuf, pulOutLen, pulNonIdent)- Applies a codepage conversion object to transform a buffer. The conversion object is created separately via the UCONV API (UCONV.DLL). This function connects the ULS string model to the codepage conversion layer.
Usage
IBM VisualAge C++ / ILINK
icc -O2 -Gm -c myapp.c ilink /PM:PM myapp.obj os2386.lib libuls.lib
OpenWatcom (wlink)
wcl386 -bt=os2 -mf -c myapp.c wlink system os2_pm file myapp.obj library os2386.lib library libuls.lib
EMX/GCC
gcc -Zomf -c myapp.c gcc -Zomf -o myapp.exe myapp.o os2386.lib libuls.lib
Include files
| Header | Contents |
|---|---|
uni.h |
Main ULS header: all Uni* prototypes; UniChar type; LocaleObject, AttrObject, TransformObject handle types; UNI_* locale type constants; ULS_SUCCESS and ULS_* error codes.
|
unidef.h |
ULS type definitions: CT_* character type flags, UCT_* Unicode category constants, LOCI_* locale item IDs.
|
ulsitem.h |
LOCALEINFOITEMS structure definition and field names.
|
Locale-aware string comparison example
#include <uni.h>
#include <unidef.h>
/* Create German locale */
LocaleObject loc;
UniCreateLocaleObject(UNI_MBS_STRING_POINTER, "de_DE", &loc);
/* Locale-correct sort (handles ä, ö, ü, ß) */
UniChar s1[] = {0x00E4, 0x0000}; /* ä */
UniChar s2[] = {0x0061, 0x0000}; /* a */
int cmp = UniStrcoll(loc, s1, s2);
/* cmp > 0: ä sorts after a in German */
/* Case conversion */
UniChar buf[] = {0x00C4, 0x0000}; /* Ä */
UniTransLower(loc, buf); /* → ä */
UniFreeLocaleObject(loc);
Date formatting example
#include <uni.h> #include <time.h> LocaleObject loc; UniCreateLocaleObject(UNI_MBS_STRING_POINTER, "fr_FR", &loc); time_t now = time(NULL); struct tm *ptm = localtime(&now); UniChar dateBuf[64]; UniStrftime(loc, dateBuf, 64, L"%A %d %B %Y", ptm); /* e.g.: "mercredi 15 janvier 2003" in French */ UniFreeLocaleObject(loc);
Relationship to Other OS/2 APIs
| API | Library | Role |
|---|---|---|
| ULS (this library) | LIBULS.LIB / LIBUNI.DLL | Locale objects, Unicode string ops, classification, formatting |
| UCONV | UCONV.LIB / UCONV.DLL | Codepage ↔ Unicode conversion objects (UniCreateUconvObject)
|
| NLS (legacy) | OS2386.LIB (COUNTRY.SYS) | Country-code/codepage based NLS: DosQueryCtryInfo, DosMapCase, DosQueryDBCSEnv
|
| LIBUNI (internal) | — | LIBUNI.DLL also contains additional internal Unicode tables used by the system |
For new OS/2 Unicode-aware applications, LIBULS.LIB (combined with UCONV.LIB for codepage conversion) is the preferred API over the older country-code NLS functions.
Version History
| Version | OS/2 release | Date | Notes |
|---|---|---|---|
| 1.0 | OS/2 Warp 4 | 1996 | Initial release of ULS with OS/2 Warp 4. Core locale object, character classification, UniStr* functions, UniStrftime.
|
| 1.1 | OS/2 Warp 4.x | 1997–1999 | Added transform objects, UniStrfmon, UniStrptime, user locale management, attr object scan, collation key generation.
|
| 1.2 | OS/2 Warp 4.52 Developer's Toolkit 4.5 | 2001 | Final IBM release. Added UniQueryNumericValue, UniQueryCharTypeTable, UniQueryStringType. File size: 7,680 bytes (2001-10-02). Source DLL: LIBUNI.DLL.
|