InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
UTF16TextCharTraits.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Chris Parrish
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __UTF16TextCharTraits__
25 #define __UTF16TextCharTraits__
26 
27 #if defined(WINDOWS) || defined(__GLIBCXX__)
28 #error This file is only for Mac libc++
29 #endif
30 
31 #if !defined(_LIBCPP_VERSION)
32 #error This file is only for Mac libc++
33 #endif
34 
35 #include <string> // for char_traits
36 #include <locale> // for codecvt
37 #include <climits>
38 
39 namespace std
40 {
41  template<>
42  struct char_traits<UTF16TextChar>
43  {
44  typedef UTF16TextChar char_type;
45  typedef unsigned short int_type;
46  typedef streampos pos_type;
47  typedef streamoff off_type;
48  typedef mbstate_t state_type;
49 
50  static void
51  assign(char_type& c1, const char_type& c2)
52  { c1 = c2; }
53 
54  static bool
55  eq(const char_type& c1, const char_type& c2)
56  { return c1 == c2; }
57 
58  static bool
59  lt(const char_type& c1, const char_type& c2)
60  { return c1 < c2; }
61 
62 
63  static int
64  compare(const char_type* s1, const char_type* s2, size_t n)
65  {
66  for (size_t i = 0; i < n; ++i)
67  {
68  if (lt(s1[i], s2[i]))
69  return -1;
70  else if (lt(s2[i], s1[i]))
71  return 1;
72  }
73  return 0;
74  }
75 
76  static size_t
77  length(const char_type* s)
78  {
79  size_t n = 0;
80  while (!eq(s[n], char_type()))
81  ++n;
82  return n;
83  }
84 
85 
86  static const char_type*
87  find(const char_type* s, size_t n, const char_type& a)
88  {
89  for (size_t i = 0; i < n; ++i)
90  {
91  if (eq(s[i], a))
92  return s + i;
93  }
94  return NULL;
95  }
96 
97  static char_type*
98  move(char_type* s1, const char_type* s2, size_t n)
99  {
100  if (s1 > s2)
101  {
102  for (size_t i = 0; i < n; ++i)
103  assign(s1[n - i - 1], s2[n - i - 1]);
104  }
105  else
106  {
107  for (size_t i = 0; i < n; ++i)
108  assign(s1[i], s2[i]);
109  }
110  return s1;
111  }
112 
113  static char_type*
114  copy(char_type* s1, const char_type* s2, size_t n)
115  {
116  for (size_t i = 0; i < n; ++i)
117  assign(s1[i], s2[i]);
118  return s1;
119  }
120 
121  static char_type*
122  assign(char_type* s, size_t n, char_type a)
123  {
124  for (size_t i = 0; i < n; ++i)
125  assign(s[i], a);
126  return s;
127  }
128 
129  static int_type
130  not_eof(const int_type& c)
131  {
132  if (eq_int_type(c, eof()))
133  return 0;
134  return c;
135  }
136 
137  static char_type
138  to_char_type(const int_type& c)
139  {
140  char_type ret;
141  ret = c;
142  return ret;
143  }
144 
145  static int_type
146  to_int_type(const char_type& c)
147  {
148  return c;
149  }
150 
151  static bool
152  eq_int_type(const int_type& c1, const int_type& c2)
153  { return c1 == c2; }
154 
155 
156  static int_type
157  eof() { return static_cast<int_type>(WEOF); }
158 
159  };
160 
161  template<>
162  class __attribute__((visibility("default"))) ctype<UTF16TextChar> : public locale::facet, public ctype_base
163  {
164  public:
165  typedef UTF16TextChar char_type;
166 
167  explicit ctype(size_t refs = 0): locale::facet(refs) { }
168 
178  bool is(mask m, char_type c) const
179  { return this->do_is(m,c); }
180 
193  const char_type* is(const char_type* low, const char_type* high, mask* vec) const
194  {
195  return this->do_is(low,high,vec);
196  }
197 
209  const char_type* scan_is(mask m, const char_type* low, const char_type* high) const
210  {return this->do_scan_is(m,low,high);}
211 
223  const char_type* scan_not(mask m, const char_type* low, const char_type* high) const
224  {return this->do_scan_not(m,low,high);}
225 
235  char_type toupper(char_type c) const
236  { return this->do_toupper(c); }
237 
248  const char_type* toupper(char_type* low, const char_type* high) const
249  { return this->do_toupper(low, high); }
250 
260  char_type tolower(char_type c) const
261  { return this->do_tolower(c); }
262 
273  const char_type* tolower(char_type* low, const char_type* high) const
274  { return this->do_tolower(low, high); }
275 
289  char_type widen(char c) const
290  { return this->do_widen(c); }
291 
307  const char* widen(const char* low, const char* high, char_type* to) const
308  { return this->do_widen(low, high, to); }
309 
325  char narrow(char_type c, char dfault) const
326  { return this->do_narrow(c, dfault); }
327 
346  const char_type* narrow(const char_type* low, const char_type* high, char dfault, char* to) const
347  { return this->do_narrow(low, high, dfault, to); }
348 
349  static locale::id id;
350 
351  protected:
352  ~ctype();
353 
354  virtual bool do_is(mask m, char_type c) const;
355 
356  virtual const char_type* do_is(const char_type* low, const char_type* high, mask* vec) const;
357 
358  virtual const char_type* do_scan_is(mask m, const char_type* low, const char_type* high) const;
359 
360  virtual const char_type* do_scan_not(mask m, const char_type* low, const char_type* high) const;
361 
362  virtual char_type do_toupper(char_type c) const;
363 
364  virtual const char_type* do_toupper(char_type* low, const char_type* high) const;
365 
366  virtual char_type do_tolower(char_type c) const;
367 
368  virtual const char_type* do_tolower(char_type* low, const char_type* high) const;
369 
370  virtual char_type do_widen(char c) const;
371 
372  virtual const char* do_widen(const char* low, const char* high, char_type* dest) const;
373 
374  virtual char do_narrow(char_type, char dfault) const;
375 
376  virtual const char_type* do_narrow(const char_type* low, const char_type* high,
377  char dfault, char* dest) const;
378  };
379 
380 
381  extern template class std::basic_string<UTF16TextChar>;
382  //extern template class std::basic_filebuf<UTF16TextChar>;
383 
384  template <>
386  : public locale::facet
387  {
388  public:
389  typedef UTF16TextChar char_type;
390  typedef basic_string<char_type> string_type;
391 
392  explicit numpunct(size_t __refs = 0);
393 
394  char_type decimal_point() const {return do_decimal_point();}
395  char_type thousands_sep() const {return do_thousands_sep();}
396  string grouping() const {return do_grouping();}
397  string_type truename() const {return do_truename();}
398  string_type falsename() const {return do_falsename();}
399 
400  static locale::id id;
401 
402  protected:
403  ~numpunct();
404  virtual char_type do_decimal_point() const;
405  virtual char_type do_thousands_sep() const;
406  virtual string do_grouping() const;
407  virtual string_type do_truename() const;
408  virtual string_type do_falsename() const;
409  };
410 
411  extern template class std::num_get<UTF16TextChar>;
412  extern template class std::num_put<UTF16TextChar>;
413  extern template class std::numpunct<UTF16TextChar>;
414  extern template class std::num_get<UTF16TextChar>;
415  extern template class std::num_put<UTF16TextChar>;
416  extern template class std::numpunct<UTF16TextChar>;
417 
418  template <>
419  class __attribute__((visibility("default"))) codecvt<UTF16TextChar, char, mbstate_t>
420  : public locale::facet,
421  public codecvt_base
422  {
423  public:
424  typedef UTF16TextChar intern_type;
425  typedef char extern_type;
426  typedef mbstate_t state_type;
427 
428 
429  explicit codecvt(size_t __refs = 0)
430  : locale::facet(__refs) {}
431 
432 
433  result out(state_type& __st,
434  const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
435  extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
436  {
437  return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
438  }
439 
440 
441  result unshift(state_type& __st,
442  extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
443  {
444  return do_unshift(__st, __to, __to_end, __to_nxt);
445  }
446 
447 
448  result in(state_type& __st,
449  const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
450  intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
451  {
452  return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
453  }
454 
455 
456  int encoding() const _NOEXCEPT
457  {
458  return do_encoding();
459  }
460 
461 
462  bool always_noconv() const _NOEXCEPT
463  {
464  return do_always_noconv();
465 }
466 
467 
468 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
469 {
470  return do_length(__st, __frm, __end, __mx);
471 }
472 
473 
474 int max_length() const _NOEXCEPT
475 {
476 return do_max_length();
477 }
478 
479 static locale::id id;
480 
481 protected:
482 
483 explicit codecvt(const char*, size_t __refs = 0)
484 : locale::facet(__refs) {}
485 
486 ~codecvt();
487 
488 virtual result do_out(state_type& __st,
489  const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
490  extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
491 virtual result do_in(state_type& __st,
492  const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
493  intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
494 virtual result do_unshift(state_type& __st,
495  extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
496 virtual int do_encoding() const _NOEXCEPT;
497 virtual bool do_always_noconv() const _NOEXCEPT;
498 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
499 virtual int do_max_length() const _NOEXCEPT;
500 };
501 
502 }
503 
504 #endif //__UTF16TextCharTraits__
505