/****************************************************************************** * * Copyright (C) 1999-2000, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* usort - library to perform locale-sensitive sorting of text lines using the usort library. for the IBM Classes for Unicode <http://www10.software.ibm.com/developerworks/opensource/icu> Steven R. Loomis <srl@monkey.sbay.org> Usage: mySort = usort_open().. usort_addLinesFromFile() or usort_addLine() .. usort_sort() .. for(i=0;i< mySort->count;i++) doSomethingWithLine(mySort->lines[i]); OR usort_print().. usort_close() .. Future Features: allow use of a custom sort algorithm ? */ #ifndef USORT_H #define USORT_H #ifdef _WIN32 #include <string.h> #endif #include "unicode/ustring.h" /*Deals with imports and exports of the dynamic library*/ #ifdef _WIN32 #define T_USORT_EXPORT __declspec(dllexport) #define T_USORT_IMPORT __declspec(dllimport) #else #define T_USORT_EXPORT #define T_USORT_IMPORT #endif #ifdef __cplusplus #define C_USORT_API extern "C" #else #define C_USORT_API #endif #ifdef T_USORT_IMPLEMENTATION #define T_USORT_API C_USORT_API T_USORT_EXPORT #define T_USORT_EXPORT_API T_USORT_EXPORT #else #define T_USORT_API C_USORT_API T_USORT_IMPORT #define T_USORT_EXPORT_API T_USORT_IMPORT #endif #include <unicode/utypes.h> #include <unicode/ucol.h> #include <unicode/ucnv.h> #include <unicode/uloc.h> #include <stdio.h> /* for FILE*'s */ typedef struct { uint8_t *key; /* Opaque key for this line. 0wned. */ int32_t keySize; /* size of above struct */ #ifdef WIN32 /*const*/ UChar *chars; /* Null terminated string. Can be 0wned. */ #else const UChar *chars; /* Null terminated string. Can be 0wned. */ #endif void *userData;/* User data */ } USortLine; typedef struct { USortLine *lines; /* the list of lines to be sorted. 0wned. */ int32_t size; /* the size of the list */ int32_t count; /* the # of actual lines */ bool_t ownsText; /* True of the lineList owns the chars. */ UCollator *collator; /* Collator for text. 0wned. */ } USort; T_USORT_API USort* usort_open(const char *locale, UCollationStrength strength, bool_t ownText, UErrorCode *status); T_USORT_API void usort_close(USort *usort); T_USORT_API void usort_addLine(USort *usort, const UChar *line, int32_t len, bool_t copy, void *userData); T_USORT_API void usort_addLinesFromFILE( USort *sort, FILE *file, UConverter *inConverter, bool_t escapeMode); T_USORT_API void usort_sort(USort *usort); T_USORT_API void usort_printToFILE(USort *usort, FILE *file, UConverter *toConverter); #endif /* _USORT */