18393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius/*
28393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius**********************************************************************
38393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius*   Copyright (C) 2013, International Business Machines
48393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius*   Corporation and others.  All Rights Reserved.
58393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius**********************************************************************
68393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius*
78393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius* scriptset.h
88393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius*
98393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius* created on: 2013 Jan 7
108393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius* created by: Andy Heninger
118393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius*/
128393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
138393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius#ifndef __SCRIPTSET_H__
148393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius#define __SCRIPTSET_H__
158393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
168393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius#include "unicode/utypes.h"
178393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius#include "unicode/uobject.h"
188393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius#include "unicode/uscript.h"
198393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
208393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius#include "uelement.h"
218393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
228393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig CorneliusU_NAMESPACE_BEGIN
238393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
248393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius//-------------------------------------------------------------------------------
258393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius//
268393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius//  ScriptSet - A bit set representing a set of scripts.
278393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius//
288393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius//              This class was originally used exclusively with script sets appearing
298393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius//              as part of the spoof check whole script confusable binary data. Its
308393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius//              use has since become more general, but the continued use to wrap
318393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius//              prebuilt binary data does constrain the design.
328393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius//
338393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius//-------------------------------------------------------------------------------
348393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Corneliusclass U_I18N_API ScriptSet: public UMemory {
358393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  public:
368393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    ScriptSet();
378393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    ScriptSet(const ScriptSet &other);
388393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    ~ScriptSet();
398393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
408393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    UBool operator == (const ScriptSet &other) const;
418393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    ScriptSet & operator = (const ScriptSet &other);
428393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
438393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    UBool      test(UScriptCode script, UErrorCode &status) const;
448393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    ScriptSet &Union(const ScriptSet &other);
458393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    ScriptSet &set(UScriptCode script, UErrorCode &status);
468393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    ScriptSet &reset(UScriptCode script, UErrorCode &status);
478393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    ScriptSet &intersect(const ScriptSet &other);
488393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    ScriptSet &intersect(UScriptCode script, UErrorCode &status);
498393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    UBool      intersects(const ScriptSet &other) const;  // Sets contain at least one script in commmon.
508393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    UBool      contains(const ScriptSet &other) const;    // All set bits in other are also set in this.
518393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
528393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    ScriptSet &setAll();
538393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    ScriptSet &resetAll();
548393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    int32_t countMembers() const;
558393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    int32_t hashCode() const;
568393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    int32_t nextSetBit(int32_t script) const;
578393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
588393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    UnicodeString &displayScripts(UnicodeString &dest) const; // append script names to dest string.
598393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    ScriptSet & parseScripts(const UnicodeString &scriptsString, UErrorCode &status);  // Replaces ScriptSet contents.
608393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
618393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius  private:
628393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius    uint32_t  bits[6];
638393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius};
648393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
658393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig CorneliusU_NAMESPACE_END
668393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
678393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig CorneliusU_CAPI UBool U_EXPORT2
688393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Corneliusuhash_compareScriptSet(const UElement key1, const UElement key2);
698393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
708393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig CorneliusU_CAPI int32_t U_EXPORT2
718393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Corneliusuhash_hashScriptSet(const UElement key);
728393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
738393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig CorneliusU_CAPI void U_EXPORT2
748393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Corneliusuhash_deleteScriptSet(void *obj);
758393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius
768393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius#endif // __SCRIPTSET_H__
77