File indexing completed on 2026-05-10 08:44:35
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef LLVM_SUPPORT_UNICODECHARRANGES_H
0009 #define LLVM_SUPPORT_UNICODECHARRANGES_H
0010
0011 #include "llvm/ADT/ArrayRef.h"
0012 #include "llvm/Support/Compiler.h"
0013 #include "llvm/Support/Debug.h"
0014 #include "llvm/Support/raw_ostream.h"
0015 #include <algorithm>
0016
0017 #define DEBUG_TYPE "unicode"
0018
0019 namespace llvm {
0020 namespace sys {
0021
0022
0023 struct UnicodeCharRange {
0024 uint32_t Lower;
0025 uint32_t Upper;
0026 };
0027
0028 inline bool operator<(uint32_t Value, UnicodeCharRange Range) {
0029 return Value < Range.Lower;
0030 }
0031 inline bool operator<(UnicodeCharRange Range, uint32_t Value) {
0032 return Range.Upper < Value;
0033 }
0034
0035
0036
0037
0038 class UnicodeCharSet {
0039 public:
0040 typedef ArrayRef<UnicodeCharRange> CharRanges;
0041
0042
0043
0044
0045
0046
0047
0048
0049 #ifdef NDEBUG
0050
0051
0052
0053
0054
0055 constexpr UnicodeCharSet(CharRanges Ranges) : Ranges(Ranges) {}
0056 #else
0057 UnicodeCharSet(CharRanges Ranges) : Ranges(Ranges) {
0058 assert(rangesAreValid());
0059 }
0060 #endif
0061
0062
0063
0064 bool contains(uint32_t C) const {
0065 return std::binary_search(Ranges.begin(), Ranges.end(), C);
0066 }
0067
0068 private:
0069
0070
0071 bool rangesAreValid() const {
0072 uint32_t Prev = 0;
0073 for (CharRanges::const_iterator I = Ranges.begin(), E = Ranges.end();
0074 I != E; ++I) {
0075 if (I != Ranges.begin() && Prev >= I->Lower) {
0076 LLVM_DEBUG(dbgs() << "Upper bound 0x");
0077 LLVM_DEBUG(dbgs().write_hex(Prev));
0078 LLVM_DEBUG(dbgs() << " should be less than succeeding lower bound 0x");
0079 LLVM_DEBUG(dbgs().write_hex(I->Lower) << "\n");
0080 return false;
0081 }
0082 if (I->Upper < I->Lower) {
0083 LLVM_DEBUG(dbgs() << "Upper bound 0x");
0084 LLVM_DEBUG(dbgs().write_hex(I->Lower));
0085 LLVM_DEBUG(dbgs() << " should not be less than lower bound 0x");
0086 LLVM_DEBUG(dbgs().write_hex(I->Upper) << "\n");
0087 return false;
0088 }
0089 Prev = I->Upper;
0090 }
0091
0092 return true;
0093 }
0094
0095 const CharRanges Ranges;
0096 };
0097
0098 }
0099 }
0100
0101 #undef DEBUG_TYPE
0102
0103 #endif