scriptset.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (C) 2013, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. *
  9. * scriptset.h
  10. *
  11. * created on: 2013 Jan 7
  12. * created by: Andy Heninger
  13. */
  14. #ifndef __SCRIPTSET_H__
  15. #define __SCRIPTSET_H__
  16. #include "unicode/utypes.h"
  17. #include "unicode/uobject.h"
  18. #include "unicode/uscript.h"
  19. #include "uelement.h"
  20. U_NAMESPACE_BEGIN
  21. //-------------------------------------------------------------------------------
  22. //
  23. // ScriptSet - A bit set representing a set of scripts.
  24. //
  25. // This class was originally used exclusively with script sets appearing
  26. // as part of the spoof check whole script confusable binary data. Its
  27. // use has since become more general, but the continued use to wrap
  28. // prebuilt binary data does constrain the design.
  29. //
  30. //-------------------------------------------------------------------------------
  31. class U_I18N_API ScriptSet: public UMemory {
  32. public:
  33. static constexpr int32_t SCRIPT_LIMIT = 224; // multiple of 32!
  34. ScriptSet();
  35. ScriptSet(const ScriptSet &other);
  36. ~ScriptSet();
  37. UBool operator == (const ScriptSet &other) const;
  38. UBool operator != (const ScriptSet &other) const {return !(*this == other);}
  39. ScriptSet & operator = (const ScriptSet &other);
  40. UBool test(UScriptCode script, UErrorCode &status) const;
  41. ScriptSet &Union(const ScriptSet &other);
  42. ScriptSet &set(UScriptCode script, UErrorCode &status);
  43. ScriptSet &reset(UScriptCode script, UErrorCode &status);
  44. ScriptSet &intersect(const ScriptSet &other);
  45. ScriptSet &intersect(UScriptCode script, UErrorCode &status);
  46. UBool intersects(const ScriptSet &other) const; // Sets contain at least one script in commmon.
  47. UBool contains(const ScriptSet &other) const; // All set bits in other are also set in this.
  48. ScriptSet &setAll();
  49. ScriptSet &resetAll();
  50. int32_t countMembers() const;
  51. int32_t hashCode() const;
  52. int32_t nextSetBit(int32_t script) const;
  53. UBool isEmpty() const;
  54. UnicodeString &displayScripts(UnicodeString &dest) const; // append script names to dest string.
  55. ScriptSet & parseScripts(const UnicodeString &scriptsString, UErrorCode &status); // Replaces ScriptSet contents.
  56. // Wraps around UScript::getScriptExtensions() and adds the corresponding scripts to this instance.
  57. void setScriptExtensions(UChar32 codePoint, UErrorCode& status);
  58. private:
  59. uint32_t bits[SCRIPT_LIMIT / 32];
  60. };
  61. U_NAMESPACE_END
  62. U_CAPI UBool U_EXPORT2
  63. uhash_compareScriptSet(const UElement key1, const UElement key2);
  64. U_CAPI int32_t U_EXPORT2
  65. uhash_hashScriptSet(const UElement key);
  66. U_CAPI void U_EXPORT2
  67. uhash_deleteScriptSet(void *obj);
  68. #endif // __SCRIPTSET_H__