HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_IdnaName.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_IdnaName.h
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UT_IDNANAME_H__
13 #define __UT_IDNANAME_H__
14 
15 #include "UT_API.h"
16 
17 #include <UT/UT_ErrorCode.h>
18 #include <UT/UT_StringHolder.h>
19 
21 {
22 public:
23  UT_IdnaName() = default;
24 
25  static bool machineName(UT_IdnaName& name, UT_ErrorCode& ec);
26  static bool create(
27  const UT_StringRef& name_utf8,
28  UT_IdnaName& out,
29  UT_ErrorCode& ec);
30 
31  const UT_StringHolder& name() const noexcept { return myALabel; }
32  const UT_StringHolder& display() const { return ulabel(); }
33 
34  const UT_StringHolder& alabel() const noexcept { return name(); }
35  const UT_StringHolder& ulabel() const
36  {
37  ensureULabel_();
38  return myULabelCache;
39  }
40 
41  bool setName(const UT_StringRef& utf8, UT_ErrorCode* ec = nullptr);
42 
43  bool isEmpty() const noexcept { return myALabel.isEmpty(); }
44 
46  {
47  ensureULabel_();
48  // If the value is already ascii then its just going to be the same
49  // value displayed twice
50  if (myULabelCache == myALabel)
51  return myALabel;
52 
53  UT_StringHolder str;
54  str.format("{} ({})", myULabelCache, myALabel);
55  return str;
56  }
57 
58  bool operator==(const UT_IdnaName& other) const noexcept
59  {
60  return myALabel.equal(other.myALabel, true);
61  }
62  bool operator!=(const UT_IdnaName& other) const noexcept
63  {
64  return !(*this == other);
65  }
66 
67  struct Hasher
68  {
69  size_t operator()(const UT_IdnaName& h) const noexcept
70  {
71  return h.alabel().toLower().hash();
72  }
73  };
74 
75 private:
76  void ensureULabel_() const;
77 
78  UT_StringHolder myALabel;
79  mutable UT_StringHolder myULabelCache;
80  mutable bool myULabelCached = false;
81 };
82 
83 namespace std
84 {
85 template <>
86 struct hash<UT_IdnaName>
87 {
88  size_t operator()(const UT_IdnaName& h) const noexcept
89  {
90  return UT_IdnaName::Hasher{}(h);
91  }
92 };
93 } // namespace std
94 
95 #endif // __UT_IDNANAME_H__
const UT_StringHolder & alabel() const noexcept
Definition: UT_IdnaName.h:34
const UT_StringHolder & name() const noexcept
Definition: UT_IdnaName.h:31
#define UT_API
Definition: UT_API.h:14
bool operator!=(const UT_IdnaName &other) const noexcept
Definition: UT_IdnaName.h:62
const UT_StringHolder & ulabel() const
Definition: UT_IdnaName.h:35
size_t operator()(const UT_IdnaName &h) const noexcept
Definition: UT_IdnaName.h:69
GLuint const GLchar * name
Definition: glcorearb.h:786
size_t format(const char *fmt, const Args &...args)
Format a string using the same formatting codes as UTformat.
bool isEmpty() const noexcept
Definition: UT_IdnaName.h:43
size_t operator()(const UT_IdnaName &h) const noexcept
Definition: UT_IdnaName.h:88
std::error_code UT_ErrorCode
Definition: UT_ErrorCode.h:20
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
const UT_StringHolder & display() const
Definition: UT_IdnaName.h:32
char utf8
Definition: SYS_Types.h:52
UT_StringHolder full() const
Definition: UT_IdnaName.h:45
bool operator==(const UT_IdnaName &other) const noexcept
Definition: UT_IdnaName.h:58