fcstring.fncs revision 1cc69409
12c393a42Smrg/* 2a6844aabSmrg * fontconfig/doc/fcstring.fncs 32c393a42Smrg * 42c393a42Smrg * Copyright © 2003 Keith Packard 52c393a42Smrg * 62c393a42Smrg * Permission to use, copy, modify, distribute, and sell this software and its 72c393a42Smrg * documentation for any purpose is hereby granted without fee, provided that 82c393a42Smrg * the above copyright notice appear in all copies and that both that 92c393a42Smrg * copyright notice and this permission notice appear in supporting 10ca08ab68Smrg * documentation, and that the name of the author(s) not be used in 112c393a42Smrg * advertising or publicity pertaining to distribution of the software without 12ca08ab68Smrg * specific, written prior permission. The authors make no 132c393a42Smrg * representations about the suitability of this software for any purpose. It 142c393a42Smrg * is provided "as is" without express or implied warranty. 152c393a42Smrg * 16a6844aabSmrg * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 172c393a42Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 18a6844aabSmrg * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR 192c393a42Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 202c393a42Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 212c393a42Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 222c393a42Smrg * PERFORMANCE OF THIS SOFTWARE. 232c393a42Smrg */ 242c393a42Smrg <variablelist> 252c393a42Smrg 261cc69409Smrg@RET@ int 271cc69409Smrg@FUNC@ FcUtf8ToUcs4 281cc69409Smrg@TYPE1@ FcChar8 * @ARG1@ src 291cc69409Smrg@TYPE2@ FcChar32 * @ARG2@ dst 301cc69409Smrg@TYPE3@ int% @ARG3@ len 311cc69409Smrg@PURPOSE@ convert UTF-8 to UCS4 322c393a42Smrg@DESC@ 332c393a42SmrgConverts the next Unicode char from <parameter>src</parameter> into 342c393a42Smrg<parameter>dst</parameter> and returns the number of bytes containing the 352c393a42Smrgchar. <parameter>src</parameter> must be at least 362c393a42Smrg<parameter>len</parameter> bytes long. 372c393a42Smrg@@ 382c393a42Smrg 391cc69409Smrg@RET@ int 401cc69409Smrg@FUNC@ FcUcs4ToUtf8 411cc69409Smrg@TYPE1@ FcChar32% @ARG1@ src 421cc69409Smrg@TYPE2@ FcChar8% @ARG2@ dst[FC_UTF8_MAX_LEN] 431cc69409Smrg@PURPOSE@ convert UCS4 to UTF-8 442c393a42Smrg@DESC@ 452c393a42SmrgConverts the Unicode char from <parameter>src</parameter> into 462c393a42Smrg<parameter>dst</parameter> and returns the number of bytes needed to encode 472c393a42Smrgthe char. 482c393a42Smrg@@ 492c393a42Smrg 501cc69409Smrg@RET@ FcBool 511cc69409Smrg@FUNC@ FcUtf8Len 521cc69409Smrg@TYPE1@ FcChar8 * @ARG1@ src 531cc69409Smrg@TYPE2@ int% @ARG2@ len 541cc69409Smrg@TYPE3@ int * @ARG3@ nchar 551cc69409Smrg@TYPE4@ int * @ARG4@ wchar 561cc69409Smrg@PURPOSE@ count UTF-8 encoded chars 572c393a42Smrg@DESC@ 582c393a42SmrgCounts the number of Unicode chars in <parameter>len</parameter> bytes of 592c393a42Smrg<parameter>src</parameter>. Places that count in 602c393a42Smrg<parameter>nchar</parameter>. <parameter>wchar</parameter> contains 1, 2 or 61ca08ab68Smrg4 depending on the number of bytes needed to hold the largest Unicode char 622c393a42Smrgcounted. The return value indicates whether <parameter>src</parameter> is a 632c393a42Smrgwell-formed UTF8 string. 642c393a42Smrg@@ 652c393a42Smrg 661cc69409Smrg@RET@ int 671cc69409Smrg@FUNC@ FcUtf16ToUcs4 681cc69409Smrg@TYPE1@ FcChar8 * @ARG1@ src 691cc69409Smrg@TYPE2@ FcEndian% @ARG2@ endian 701cc69409Smrg@TYPE3@ FcChar32 * @ARG3@ dst 711cc69409Smrg@TYPE4@ int% @ARG4@ len 721cc69409Smrg@PURPOSE@ convert UTF-16 to UCS4 732c393a42Smrg@DESC@ 742c393a42SmrgConverts the next Unicode char from <parameter>src</parameter> into 752c393a42Smrg<parameter>dst</parameter> and returns the number of bytes containing the 762c393a42Smrgchar. <parameter>src</parameter> must be at least <parameter>len</parameter> 772c393a42Smrgbytes long. Bytes of <parameter>src</parameter> are combined into 16-bit 782c393a42Smrgunits according to <parameter>endian</parameter>. 792c393a42Smrg@@ 802c393a42Smrg 811cc69409Smrg@RET@ FcBool 821cc69409Smrg@FUNC@ FcUtf16Len 831cc69409Smrg@TYPE1@ FcChar8 * @ARG1@ src 841cc69409Smrg@TYPE2@ FcEndian% @ARG2@ endian 851cc69409Smrg@TYPE3@ int% @ARG3@ len 861cc69409Smrg@TYPE4@ int * @ARG4@ nchar 871cc69409Smrg@TYPE5@ int * @ARG5@ wchar 881cc69409Smrg@PURPOSE@ count UTF-16 encoded chars 892c393a42Smrg@DESC@ 902c393a42SmrgCounts the number of Unicode chars in <parameter>len</parameter> bytes of 912c393a42Smrg<parameter>src</parameter>. Bytes of <parameter>src</parameter> are 922c393a42Smrgcombined into 16-bit units according to <parameter>endian</parameter>. 932c393a42SmrgPlaces that count in <parameter>nchar</parameter>. 942c393a42Smrg<parameter>wchar</parameter> contains 1, 2 or 4 depending on the number of 95ca08ab68Smrgbytes needed to hold the largest Unicode char counted. The return value 962c393a42Smrgindicates whether <parameter>string</parameter> is a well-formed UTF16 972c393a42Smrgstring. 982c393a42Smrg@@ 992c393a42Smrg 1001cc69409Smrg@RET@ FcBool 1011cc69409Smrg@FUNC@ FcIsLower 1021cc69409Smrg@TYPE1@ FcChar8 @ARG1@ c 1031cc69409Smrg@PURPOSE@ check for lower case ASCII character 1042c393a42Smrg@DESC@ 1052c393a42SmrgThis macro checks whether <parameter>c</parameter> is an lower case ASCII 1062c393a42Smrgletter. 1072c393a42Smrg@@ 1082c393a42Smrg 1091cc69409Smrg@RET@ FcBool 1101cc69409Smrg@FUNC@ FcIsUpper 1111cc69409Smrg@TYPE1@ FcChar8 @ARG1@ c 1121cc69409Smrg@PURPOSE@ check for upper case ASCII character 1132c393a42Smrg@DESC@ 1142c393a42SmrgThis macro checks whether <parameter>c</parameter> is a upper case ASCII 1152c393a42Smrgletter. 1162c393a42Smrg@@ 1172c393a42Smrg 1181cc69409Smrg@RET@ FcChar8 1191cc69409Smrg@FUNC@ FcToLower 1201cc69409Smrg@TYPE1@ FcChar8 @ARG1@ c 1211cc69409Smrg@PURPOSE@ convert upper case ASCII to lower case 1222c393a42Smrg@DESC@ 1232c393a42SmrgThis macro converts upper case ASCII <parameter>c</parameter> to the 1242c393a42Smrgequivalent lower case letter. 1252c393a42Smrg@@ 1262c393a42Smrg 1271cc69409Smrg@RET@ FcChar8 * 1281cc69409Smrg@FUNC@ FcStrCopy 1291cc69409Smrg@TYPE1@ const FcChar8 * @ARG1@ s 1301cc69409Smrg@PURPOSE@ duplicate a string 1312c393a42Smrg@DESC@ 1322c393a42SmrgAllocates memory, copies <parameter>s</parameter> and returns the resulting 1332c393a42Smrgbuffer. Yes, this is <function>strdup</function>, but that function isn't 1342c393a42Smrgavailable on every platform. 1352c393a42Smrg@@ 1362c393a42Smrg 1371cc69409Smrg@RET@ FcChar8 * 1381cc69409Smrg@FUNC@ FcStrDowncase 1391cc69409Smrg@TYPE1@ const FcChar8 * @ARG1@ s 1401cc69409Smrg@PURPOSE@ create a lower case translation of a string 1412c393a42Smrg@DESC@ 1422c393a42SmrgAllocates memory, copies <parameter>s</parameter>, converting upper case 1432c393a42Smrgletters to lower case and returns the allocated buffer. 1442c393a42Smrg@@ 1452c393a42Smrg 1461cc69409Smrg@RET@ FcChar8 * 1471cc69409Smrg@FUNC@ FcStrCopyFilename 1481cc69409Smrg@TYPE1@ const FcChar8 * @ARG1@ s 1491cc69409Smrg@PURPOSE@ create a complete path from a filename 1502c393a42Smrg@DESC@ 1512c393a42Smrg<function>FcStrCopyFilename</function> constructs an absolute pathname from 1522c393a42Smrg<parameter>s</parameter>. It converts any leading '~' characters in 1532c393a42Smrgto the value of the HOME environment variable, and any relative paths are 1542c393a42Smrgconverted to absolute paths using the current working directory. Sequences 1552c393a42Smrgof '/' characters are converted to a single '/', and names containing the 1562c393a42Smrgcurrent directory '.' or parent directory '..' are correctly reconstructed. 1572c393a42SmrgReturns NULL if '~' is the leading character and HOME is unset or disabled 1582c393a42Smrg(see <function>FcConfigEnableHome</function>). 1592c393a42Smrg@@ 1602c393a42Smrg 1611cc69409Smrg@RET@ int 1621cc69409Smrg@FUNC@ FcStrCmp 1631cc69409Smrg@TYPE1@ const FcChar8 * @ARG1@ s1 1641cc69409Smrg@TYPE2@ const FcChar8 * @ARG2@ s2 1651cc69409Smrg@PURPOSE@ compare UTF-8 strings 1662c393a42Smrg@DESC@ 1672c393a42SmrgReturns the usual <0, 0, >0 result of comparing 1681cc69409Smrg<parameter>s1</parameter> and <parameter>s2</parameter>. 1692c393a42Smrg@@ 1702c393a42Smrg 1711cc69409Smrg@RET@ int 1721cc69409Smrg@FUNC@ FcStrCmpIgnoreCase 1731cc69409Smrg@TYPE1@ const FcChar8 * @ARG1@ s1 1741cc69409Smrg@TYPE2@ const FcChar8 * @ARG2@ s2 1751cc69409Smrg@PURPOSE@ compare UTF-8 strings ignoring case 1762c393a42Smrg@DESC@ 1772c393a42SmrgReturns the usual <0, 0, >0 result of comparing 1782c393a42Smrg<parameter>s1</parameter> and <parameter>s2</parameter>. This test is 1792c393a42Smrgcase-insensitive for all proper UTF-8 encoded strings. 1802c393a42Smrg@@ 1812c393a42Smrg 1821cc69409Smrg@RET@ FcChar8 * 1831cc69409Smrg@FUNC@ FcStrStr 1841cc69409Smrg@TYPE1@ const FcChar8 * @ARG1@ s1 1851cc69409Smrg@TYPE2@ const FcChar8 * @ARG2@ s2 1861cc69409Smrg@PURPOSE@ locate UTF-8 substring 1872c393a42Smrg@DESC@ 1882c393a42SmrgReturns the location of <parameter>s2</parameter> in 1892c393a42Smrg<parameter>s1</parameter>. Returns NULL if <parameter>s2</parameter> 1902c393a42Smrgis not present in <parameter>s1</parameter>. This test will operate properly 1912c393a42Smrgwith UTF8 encoded strings. 1922c393a42Smrg@@ 1932c393a42Smrg 1941cc69409Smrg@RET@ FcChar8 * 1951cc69409Smrg@FUNC@ FcStrStrIgnoreCase 1961cc69409Smrg@TYPE1@ const FcChar8 * @ARG1@ s1 1971cc69409Smrg@TYPE2@ const FcChar8 * @ARG2@ s2 1981cc69409Smrg@PURPOSE@ locate UTF-8 substring ignoring case 1992c393a42Smrg@DESC@ 2001cc69409SmrgReturns the location of <parameter>s2</parameter> in 2012c393a42Smrg<parameter>s1</parameter>, ignoring case. Returns NULL if 2022c393a42Smrg<parameter>s2</parameter> is not present in <parameter>s1</parameter>. 2032c393a42SmrgThis test is case-insensitive for all proper UTF-8 encoded strings. 2042c393a42Smrg@@ 2052c393a42Smrg 2061cc69409Smrg@RET@ FcChar8 * 2071cc69409Smrg@FUNC@ FcStrPlus 2081cc69409Smrg@TYPE1@ const FcChar8 * @ARG1@ s1 2091cc69409Smrg@TYPE2@ const FcChar8 * @ARG2@ s2 2101cc69409Smrg@PURPOSE@ concatenate two strings 2112c393a42Smrg@DESC@ 2122c393a42SmrgThis function allocates new storage and places the concatenation of 2132c393a42Smrg<parameter>s1</parameter> and <parameter>s2</parameter> there, returning the 2142c393a42Smrgnew string. 2152c393a42Smrg@@ 2162c393a42Smrg 2171cc69409Smrg@RET@ void 2181cc69409Smrg@FUNC@ FcStrFree 2191cc69409Smrg@TYPE1@ FcChar8 * @ARG1@ s 2201cc69409Smrg@PURPOSE@ free a string 2212c393a42Smrg@DESC@ 2222c393a42SmrgThis is just a wrapper around free(3) which helps track memory usage of 2232c393a42Smrgstrings within the fontconfig library. 2242c393a42Smrg@@ 2252c393a42Smrg 2261cc69409Smrg@RET@ FcChar8 * 2271cc69409Smrg@FUNC@ FcStrBuildFilename 2281cc69409Smrg@TYPE1@ const FcChar8 * @ARG1@ path 2291cc69409Smrg@TYPE2@ ... 2301cc69409Smrg@PURPOSE@ Concatenate strings as a file path 231a4e54154Smrg@DESC@ 232a4e54154SmrgCreates a filename from the given elements of strings as file paths 233a4e54154Smrgand concatenate them with the appropriate file separator. 234a4e54154SmrgArguments must be null-terminated. 235a4e54154SmrgThis returns a newly-allocated memory which should be freed when no longer needed. 236a4e54154Smrg@@ 237a4e54154Smrg 2381cc69409Smrg@RET@ FcChar8 * 2391cc69409Smrg@FUNC@ FcStrDirname 2401cc69409Smrg@TYPE1@ const FcChar8 * @ARG1@ file 2411cc69409Smrg@PURPOSE@ directory part of filename 2422c393a42Smrg@DESC@ 2432c393a42SmrgReturns the directory containing <parameter>file</parameter>. This 2442c393a42Smrgis returned in newly allocated storage which should be freed when no longer 2452c393a42Smrgneeded. 2462c393a42Smrg@@ 2472c393a42Smrg 2481cc69409Smrg@RET@ FcChar8 * 2491cc69409Smrg@FUNC@ FcStrBasename 2501cc69409Smrg@TYPE1@ const FcChar8 * @ARG1@ file 2511cc69409Smrg@PURPOSE@ last component of filename 2522c393a42Smrg@DESC@ 2532c393a42SmrgReturns the filename of <parameter>file</parameter> stripped of any leading 2542c393a42Smrgdirectory names. This is returned in newly allocated storage which should 2552c393a42Smrgbe freed when no longer needed. 2562c393a42Smrg@@ 257