12e5b6d6dSopenharmony_ci// © 2017 and later: Unicode, Inc. and others. 22e5b6d6dSopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html 32e5b6d6dSopenharmony_ci#ifndef COLPROBE_SORTEDLINES_H 42e5b6d6dSopenharmony_ci#define COLPROBE_SORTEDLINES_H 52e5b6d6dSopenharmony_ci 62e5b6d6dSopenharmony_ci// colprobe includes 72e5b6d6dSopenharmony_ci#include "colprobe.h" 82e5b6d6dSopenharmony_ci#include "line.h" 92e5b6d6dSopenharmony_ci#include "uprinter.h" 102e5b6d6dSopenharmony_ci#include "strengthprobe.h" 112e5b6d6dSopenharmony_ci 122e5b6d6dSopenharmony_ci 132e5b6d6dSopenharmony_ci// ICU includes 142e5b6d6dSopenharmony_ci#include "unicode/uniset.h" 152e5b6d6dSopenharmony_ci#include "unicode/usetiter.h" 162e5b6d6dSopenharmony_ci#include "unicode/uscript.h" 172e5b6d6dSopenharmony_ci#include "hash.h" 182e5b6d6dSopenharmony_ci 192e5b6d6dSopenharmony_ciclass SortedLines { 202e5b6d6dSopenharmony_ci Line empty; 212e5b6d6dSopenharmony_ci Line *UB[UCOL_OFF]; 222e5b6d6dSopenharmony_ci UnicodeSet ignorables[UCOL_OFF]; 232e5b6d6dSopenharmony_ci 242e5b6d6dSopenharmony_ci Line **toSort; 252e5b6d6dSopenharmony_ci int32_t toSortCapacity; 262e5b6d6dSopenharmony_ci Line *lines; 272e5b6d6dSopenharmony_ci int32_t size; 282e5b6d6dSopenharmony_ci int32_t capacity; 292e5b6d6dSopenharmony_ci 302e5b6d6dSopenharmony_ci UnicodeSet repertoire; 312e5b6d6dSopenharmony_ci UnicodeSet excludeBounds; 322e5b6d6dSopenharmony_ci 332e5b6d6dSopenharmony_ci StrengthProbe probe; 342e5b6d6dSopenharmony_ci 352e5b6d6dSopenharmony_ci Line *first; 362e5b6d6dSopenharmony_ci Line *last; 372e5b6d6dSopenharmony_ci Line *current; 382e5b6d6dSopenharmony_ci SortedLines() {}; 392e5b6d6dSopenharmony_ci 402e5b6d6dSopenharmony_ci UPrinter *logger; 412e5b6d6dSopenharmony_ci UPrinter *debug; 422e5b6d6dSopenharmony_ci 432e5b6d6dSopenharmony_ci Hashtable *contractionsTable; 442e5b6d6dSopenharmony_ci Hashtable *duplicators; // elements that duplicate preceding characters 452e5b6d6dSopenharmony_ci int32_t maxExpansionPrefixSize; 462e5b6d6dSopenharmony_ci 472e5b6d6dSopenharmony_ci // Properties of the sort 482e5b6d6dSopenharmony_ci UBool wordSort; 492e5b6d6dSopenharmony_ci UBool frenchSecondary; 502e5b6d6dSopenharmony_ci UBool upperFirst; 512e5b6d6dSopenharmony_ci 522e5b6d6dSopenharmony_ci uint8_t *sortkeys; 532e5b6d6dSopenharmony_ci int32_t sortkeyOffset; 542e5b6d6dSopenharmony_cipublic: 552e5b6d6dSopenharmony_ci SortedLines(const UnicodeSet &set, const UnicodeSet &excludeBounds, const StrengthProbe &probe, UPrinter *logger, UPrinter *debug); 562e5b6d6dSopenharmony_ci SortedLines(FILE *file, UPrinter *logger, UPrinter *debug, UErrorCode &status); 572e5b6d6dSopenharmony_ci ~SortedLines(); 582e5b6d6dSopenharmony_ci void analyse(UErrorCode &status); 592e5b6d6dSopenharmony_ci 602e5b6d6dSopenharmony_ci void sort(UBool setStrengths = true, UBool link = false); 612e5b6d6dSopenharmony_ci void sort(Line **sortingArray, int32_t sizeToSort, UBool setStrengths = true, UBool link = false); 622e5b6d6dSopenharmony_ci 632e5b6d6dSopenharmony_ci Line *getFirst(); 642e5b6d6dSopenharmony_ci Line *getLast(); 652e5b6d6dSopenharmony_ci void add(Line *line, UBool linkIn = false); 662e5b6d6dSopenharmony_ci void insert(Line *line, int32_t index); 672e5b6d6dSopenharmony_ci Line *getNext(); 682e5b6d6dSopenharmony_ci Line *getPrevious(); 692e5b6d6dSopenharmony_ci Line *operator[](int32_t index); 702e5b6d6dSopenharmony_ci int32_t addContractionsToRepertoire(UErrorCode &status); 712e5b6d6dSopenharmony_ci 722e5b6d6dSopenharmony_ci int32_t getSize() const; 732e5b6d6dSopenharmony_ci 742e5b6d6dSopenharmony_ci int32_t detectExpansions(); 752e5b6d6dSopenharmony_ci 762e5b6d6dSopenharmony_ci UnicodeString toString(UBool useLinks = false); 772e5b6d6dSopenharmony_ci UnicodeString toStringFromEmpty(); 782e5b6d6dSopenharmony_ci UnicodeString toPrettyString(UBool useLinks, UBool printSortKeys = false); 792e5b6d6dSopenharmony_ci UnicodeString toOutput(const char *format, 802e5b6d6dSopenharmony_ci const char *locale, const char *platform, const char *reference, 812e5b6d6dSopenharmony_ci UBool useLinks, UBool initialize, UBool moreToCome); 822e5b6d6dSopenharmony_ci UnicodeString toBundle(const char *locale, const char *platform, const char *reference, 832e5b6d6dSopenharmony_ci UBool useLinks, UBool initialize, UBool moreToCome); 842e5b6d6dSopenharmony_ci UnicodeString toHTML(const char *locale, const char *platform, const char *reference, 852e5b6d6dSopenharmony_ci UBool useLinks, UBool initialize, UBool moreToCome); 862e5b6d6dSopenharmony_ci UnicodeString toXML(const char *locale, const char *platform, const char *reference, 872e5b6d6dSopenharmony_ci UBool useLinks, UBool initialize, UBool moreToCome); 882e5b6d6dSopenharmony_ci UnicodeString arrayToString(Line** sortedLines, int32_t linesSize, UBool pretty, UBool useLinks, UBool printSortKeys); 892e5b6d6dSopenharmony_ci void setSortingArray(Line **sortingArray, Line *elements, int32_t sizeToSort); 902e5b6d6dSopenharmony_ci int32_t setSortingArray(Line **sortingArray, Hashtable *table); 912e5b6d6dSopenharmony_ci 922e5b6d6dSopenharmony_ci void reduceDifference(SortedLines& reference); 932e5b6d6dSopenharmony_ci void getRepertoire(UnicodeSet &fillIn); 942e5b6d6dSopenharmony_ci void removeDecompositionsFromRepertoire(); 952e5b6d6dSopenharmony_ci void getBounds(UErrorCode &status); 962e5b6d6dSopenharmony_ci void classifyRepertoire(); 972e5b6d6dSopenharmony_ci void toFile(FILE *file, UBool useLinks, UErrorCode &status); 982e5b6d6dSopenharmony_ci void swapCase(); 992e5b6d6dSopenharmony_ci void calculateSortKeys(); 1002e5b6d6dSopenharmony_ci void calculateSortKey(Line &line); 1012e5b6d6dSopenharmony_ciprivate: 1022e5b6d6dSopenharmony_ci void init(); 1032e5b6d6dSopenharmony_ci void init(UnicodeSet &rep, Line *lin); 1042e5b6d6dSopenharmony_ci int32_t detectContractions(Line **firstRep, int32_t firstSize, 1052e5b6d6dSopenharmony_ci Line **secondRep, int32_t secondSize, 1062e5b6d6dSopenharmony_ci Line *toAddTo, int32_t &toAddToSize, 1072e5b6d6dSopenharmony_ci Line *lesserToAddTo, int32_t &lesserToAddToSize, 1082e5b6d6dSopenharmony_ci int32_t capacity, UErrorCode &status); 1092e5b6d6dSopenharmony_ci 1102e5b6d6dSopenharmony_ci void calculateCumulativeStrengths(Line *start, Line *end); 1112e5b6d6dSopenharmony_ci void transferCumulativeStrength(Line *previous, Line *that); 1122e5b6d6dSopenharmony_ci void updateBounds(UnicodeSet &set); 1132e5b6d6dSopenharmony_ci void addAll(Line* toAdd, int32_t toAddSize); 1142e5b6d6dSopenharmony_ci void setDistancesFromEmpty(Line* array, int32_t arraySize); 1152e5b6d6dSopenharmony_ci void noteContraction(const char* msg, Line *toAddTo, int32_t &toAddToSize, Line *left, Line *right, int32_t &noConts, UErrorCode &status); 1162e5b6d6dSopenharmony_ci int32_t gooseUp(int32_t resetIndex, int32_t expansionIndex, Line &expLine, int32_t *expIndexes, int32_t &expIndexSize, UColAttributeValue strength); 1172e5b6d6dSopenharmony_ci UBool getExpansionLine(const Line &expansion, const Line &previous, const Line &exp, Line &expansionLine); 1182e5b6d6dSopenharmony_ci 1192e5b6d6dSopenharmony_ci 1202e5b6d6dSopenharmony_ci}; 1212e5b6d6dSopenharmony_ci 1222e5b6d6dSopenharmony_ci#endif // #ifndef COLPROBE_SORTEDLINES_H 123