00001 /****************************************************************************** 00002 * 00003 * Copyright (C) 1999-2000, International Business Machines 00004 * Corporation and others. All Rights Reserved. 00005 * 00006 ******************************************************************************* 00007 00008 usort - library to perform locale-sensitive sorting of text lines 00009 using the usort library. 00010 00011 for the IBM Classes for Unicode 00012 <http://www10.software.ibm.com/developerworks/opensource/icu> 00013 00014 00015 Steven R. Loomis <srl@monkey.sbay.org> 00016 00017 Usage: 00018 mySort = usort_open().. 00019 usort_addLinesFromFile() or usort_addLine() .. 00020 usort_sort() .. 00021 00022 for(i=0;i< mySort->count;i++) 00023 doSomethingWithLine(mySort->lines[i]); 00024 OR 00025 usort_print().. 00026 00027 usort_close() .. 00028 00029 Future Features: 00030 allow use of a custom sort algorithm ? 00031 00032 */ 00033 00034 #ifndef USORT_H 00035 #define USORT_H 00036 00037 #ifdef _WIN32 00038 #include <string.h> 00039 #endif 00040 00041 #include "unicode/ustring.h" 00042 00043 /*Deals with imports and exports of the dynamic library*/ 00044 #ifdef _WIN32 00045 #define T_USORT_EXPORT __declspec(dllexport) 00046 #define T_USORT_IMPORT __declspec(dllimport) 00047 #else 00048 #define T_USORT_EXPORT 00049 #define T_USORT_IMPORT 00050 #endif 00051 00052 #ifdef __cplusplus 00053 #define C_USORT_API extern "C" 00054 #else 00055 #define C_USORT_API 00056 #endif 00057 00058 #ifdef T_USORT_IMPLEMENTATION 00059 #define T_USORT_API C_USORT_API T_USORT_EXPORT 00060 #define T_USORT_EXPORT_API T_USORT_EXPORT 00061 #else 00062 #define T_USORT_API C_USORT_API T_USORT_IMPORT 00063 #define T_USORT_EXPORT_API T_USORT_IMPORT 00064 #endif 00065 00066 00067 00068 00069 #include <unicode/utypes.h> 00070 #include <unicode/ucol.h> 00071 #include <unicode/ucnv.h> 00072 #include <unicode/uloc.h> 00073 #include <stdio.h> /* for FILE*'s */ 00074 00079 typedef struct 00080 { 00081 uint8_t *key; /* Opaque key for this line. 0wned. */ 00082 int32_t keySize; /* size of above struct */ 00083 #ifdef WIN32 00084 /*const*/ UChar *chars; /* Null terminated string. Can be 0wned. */ 00085 #else 00086 const UChar *chars; /* Null terminated string. Can be 0wned. */ 00087 #endif 00088 void *userData;/* User data */ 00089 } USortLine; 00090 00095 typedef struct 00096 { 00097 USortLine *lines; /* the list of lines to be sorted. 0wned. */ 00098 int32_t size; /* the size of the list */ 00099 int32_t count; /* the # of actual lines */ 00100 bool_t ownsText; /* True of the lineList owns the chars. */ 00101 UCollator *collator; /* Collator for text. 0wned. */ 00102 } USort; 00103 00112 T_USORT_API USort* 00113 usort_open(const char *locale, UCollationStrength strength, bool_t ownText, 00114 UErrorCode *status); 00115 00122 T_USORT_API void 00123 usort_close(USort *usort); 00124 00138 T_USORT_API void 00139 usort_addLine(USort *usort, const UChar *line, int32_t len, bool_t copy, void *userData); 00140 00151 T_USORT_API void 00152 usort_addLinesFromFILE( USort *sort, FILE *file, UConverter *inConverter, bool_t escapeMode); 00153 00159 T_USORT_API void 00160 usort_sort(USort *usort); 00161 00170 T_USORT_API void 00171 usort_printToFILE(USort *usort, FILE *file, UConverter *toConverter); 00172 00173 #endif /* _USORT */ 00174 00175 00176 00177 00178 00179