1 // © 2017 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 #ifndef COLPROBE_SORTEDLINES_H 4 #define COLPROBE_SORTEDLINES_H 5 6 // colprobe includes 7 #include "colprobe.h" 8 #include "line.h" 9 #include "uprinter.h" 10 #include "strengthprobe.h" 11 12 13 // ICU includes 14 #include "unicode/uniset.h" 15 #include "unicode/usetiter.h" 16 #include "unicode/uscript.h" 17 #include "hash.h" 18 19 class SortedLines { 20 Line empty; 21 Line *UB[UCOL_OFF]; 22 UnicodeSet ignorables[UCOL_OFF]; 23 24 Line **toSort; 25 int32_t toSortCapacity; 26 Line *lines; 27 int32_t size; 28 int32_t capacity; 29 30 UnicodeSet repertoire; 31 UnicodeSet excludeBounds; 32 33 StrengthProbe probe; 34 35 Line *first; 36 Line *last; 37 Line *current; SortedLines()38 SortedLines() {}; 39 40 UPrinter *logger; 41 UPrinter *debug; 42 43 Hashtable *contractionsTable; 44 Hashtable *duplicators; // elements that duplicate preceding characters 45 int32_t maxExpansionPrefixSize; 46 47 // Properties of the sort 48 UBool wordSort; 49 UBool frenchSecondary; 50 UBool upperFirst; 51 52 uint8_t *sortkeys; 53 int32_t sortkeyOffset; 54 public: 55 SortedLines(const UnicodeSet &set, const UnicodeSet &excludeBounds, const StrengthProbe &probe, UPrinter *logger, UPrinter *debug); 56 SortedLines(FILE *file, UPrinter *logger, UPrinter *debug, UErrorCode &status); 57 ~SortedLines(); 58 void analyse(UErrorCode &status); 59 60 void sort(UBool setStrengths = true, UBool link = false); 61 void sort(Line **sortingArray, int32_t sizeToSort, UBool setStrengths = true, UBool link = false); 62 63 Line *getFirst(); 64 Line *getLast(); 65 void add(Line *line, UBool linkIn = false); 66 void insert(Line *line, int32_t index); 67 Line *getNext(); 68 Line *getPrevious(); 69 Line *operator[](int32_t index); 70 int32_t addContractionsToRepertoire(UErrorCode &status); 71 72 int32_t getSize() const; 73 74 int32_t detectExpansions(); 75 76 UnicodeString toString(UBool useLinks = false); 77 UnicodeString toStringFromEmpty(); 78 UnicodeString toPrettyString(UBool useLinks, UBool printSortKeys = false); 79 UnicodeString toOutput(const char *format, 80 const char *locale, const char *platform, const char *reference, 81 UBool useLinks, UBool initialize, UBool moreToCome); 82 UnicodeString toBundle(const char *locale, const char *platform, const char *reference, 83 UBool useLinks, UBool initialize, UBool moreToCome); 84 UnicodeString toHTML(const char *locale, const char *platform, const char *reference, 85 UBool useLinks, UBool initialize, UBool moreToCome); 86 UnicodeString toXML(const char *locale, const char *platform, const char *reference, 87 UBool useLinks, UBool initialize, UBool moreToCome); 88 UnicodeString arrayToString(Line** sortedLines, int32_t linesSize, UBool pretty, UBool useLinks, UBool printSortKeys); 89 void setSortingArray(Line **sortingArray, Line *elements, int32_t sizeToSort); 90 int32_t setSortingArray(Line **sortingArray, Hashtable *table); 91 92 void reduceDifference(SortedLines& reference); 93 void getRepertoire(UnicodeSet &fillIn); 94 void removeDecompositionsFromRepertoire(); 95 void getBounds(UErrorCode &status); 96 void classifyRepertoire(); 97 void toFile(FILE *file, UBool useLinks, UErrorCode &status); 98 void swapCase(); 99 void calculateSortKeys(); 100 void calculateSortKey(Line &line); 101 private: 102 void init(); 103 void init(UnicodeSet &rep, Line *lin); 104 int32_t detectContractions(Line **firstRep, int32_t firstSize, 105 Line **secondRep, int32_t secondSize, 106 Line *toAddTo, int32_t &toAddToSize, 107 Line *lesserToAddTo, int32_t &lesserToAddToSize, 108 int32_t capacity, UErrorCode &status); 109 110 void calculateCumulativeStrengths(Line *start, Line *end); 111 void transferCumulativeStrength(Line *previous, Line *that); 112 void updateBounds(UnicodeSet &set); 113 void addAll(Line* toAdd, int32_t toAddSize); 114 void setDistancesFromEmpty(Line* array, int32_t arraySize); 115 void noteContraction(const char* msg, Line *toAddTo, int32_t &toAddToSize, Line *left, Line *right, int32_t &noConts, UErrorCode &status); 116 int32_t gooseUp(int32_t resetIndex, int32_t expansionIndex, Line &expLine, int32_t *expIndexes, int32_t &expIndexSize, UColAttributeValue strength); 117 UBool getExpansionLine(const Line &expansion, const Line &previous, const Line &exp, Line &expansionLine); 118 119 120 }; 121 122 #endif // #ifndef COLPROBE_SORTEDLINES_H 123