Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. /*
  9. *
  10. * Copyright (c) 1998-9
  11. * Dr John Maddock
  12. *
  13. * Permission to use, copy, modify, distribute and sell this software
  14. * and its documentation for any purpose is hereby granted without fee,
  15. * provided that the above copyright notice appear in all copies and
  16. * that both that copyright notice and this permission notice appear
  17. * in supporting documentation. Dr John Maddock makes no representations
  18. * about the suitability of this software for any purpose.
  19. * It is provided "as is" without express or implied warranty.
  20. *
  21. */
  22. /*
  23. * FILE regfac.h
  24. * VERSION 2.12
  25. */
  26. #ifndef REGFAC_H
  27. #define REGFAC_H
  28. #ifndef JM_CFG_H
  29. #include <jm/jm_cfg.h>
  30. #endif
  31. #ifdef RE_LOCALE_CPP
  32. #include <string>
  33. #include <jm/re_str.h>
  34. #include <jm/re_cls.h>
  35. #include <list>
  36. #include <map>
  37. //
  38. // class regfacet
  39. //
  40. // provides syntax data etc, customised versions
  41. // can be installed in an instance of std::locale and imbue'd
  42. // into a reg_expression for per-instance localisation.
  43. //
  44. JM_NAMESPACE(__JM)
  45. template <class charT>
  46. class regfacet : public __JM_STD::locale::facet
  47. {
  48. public:
  49. static __JM_STD::locale::id id;
  50. regfacet(unsigned int i = 0);
  51. jm_uintfast32_t RE_CALL lookup_classname(const charT* first, const charT* last)const;
  52. bool RE_CALL lookup_collatename(re_str<charT>& s, const re_str<charT>& name)const;
  53. unsigned int RE_CALL syntax_type(charT)const;
  54. void RE_CALL update(const __JM_STD::locale&)const;
  55. charT RE_CALL zero()const;
  56. charT RE_CALL ten()const;
  57. protected:
  58. virtual jm_uintfast32_t RE_CALL do_lookup_classname(const charT* first, const charT* last)const = 0;
  59. virtual bool RE_CALL do_lookup_collatename(re_str<charT>& s, const re_str<charT>& name)const = 0;
  60. virtual unsigned int RE_CALL do_syntax_type(charT)const = 0;
  61. virtual void RE_CALL do_update(const __JM_STD::locale&) = 0;
  62. // required by Rogue Wave, not part of standard:
  63. __JM_STD::locale::id& get_id()const { return id; }
  64. ~regfacet(){}
  65. };
  66. JM_TEMPLATE_SPECIALISE
  67. class JM_IX_DECL regfacet<char> : public __JM_STD::locale::facet
  68. {
  69. public:
  70. typedef __JM_STD::messages<char>::string_type string_type;
  71. private:
  72. unsigned char syntax_map[256];
  73. string_type name;
  74. char _zero, _ten;
  75. __JM_STD::map<__JM_STD::string, unsigned long, __JM_STD::less<__JM_STD::string> > classes;
  76. __JM_STD::map<re_str<char>, re_str<char>, __JM_STD::less<re_str<char> > > collating_elements;
  77. regfacet(const regfacet&);
  78. #ifdef RE_THREADS
  79. critical_section cs;
  80. #endif
  81. public:
  82. static __JM_STD::locale::id id;
  83. regfacet(unsigned int i = 0);
  84. jm_uintfast32_t RE_CALL lookup_classname(const char* first, const char* last)const { return do_lookup_classname(first, last); }
  85. bool RE_CALL lookup_collatename(re_str<char>& s, const re_str<char>& name)const { return do_lookup_collatename(s, name); }
  86. unsigned int RE_CALL syntax_type(char c)const { return do_syntax_type(c); }
  87. void RE_CALL update(const __JM_STD::locale& l)const { const_cast<regfacet<char>*>(this)->do_update(l); }
  88. char RE_CALL zero()const { return _zero; }
  89. char RE_CALL ten()const { return _ten; }
  90. protected:
  91. virtual jm_uintfast32_t RE_CALL do_lookup_classname(const char* first, const char* last)const;
  92. virtual bool RE_CALL do_lookup_collatename(re_str<char>& s, const re_str<char>& name)const;
  93. virtual unsigned int RE_CALL do_syntax_type(char)const;
  94. virtual void RE_CALL do_update(const __JM_STD::locale&);
  95. // required by Rogue Wave, not part of standard:
  96. __JM_STD::locale::id& get_id()const { return id; }
  97. ~regfacet();
  98. };
  99. JM_TEMPLATE_SPECIALISE
  100. class JM_IX_DECL regfacet<wchar_t> : public __JM_STD::locale::facet
  101. {
  102. public:
  103. typedef __JM_STD::messages<wchar_t>::string_type string_type;
  104. private:
  105. __JM_STD::messages<char>::string_type name;
  106. struct syntax_map
  107. {
  108. wchar_t c;
  109. unsigned int type;
  110. };
  111. __JM_STD::list<syntax_map> syntax;
  112. wchar_t _zero, _ten;
  113. __JM_STD::map<__JM_STD::wstring, unsigned long, __JM_STD::less<__JM_STD::wstring> > classes;
  114. const __JM_STD::locale* ploc;
  115. __JM_STD::map<re_str<wchar_t>, re_str<wchar_t>, __JM_STD::less<re_str<wchar_t> > > collating_elements;
  116. regfacet(const regfacet&);
  117. #ifdef RE_THREADS
  118. critical_section cs;
  119. #endif
  120. public:
  121. static __JM_STD::locale::id id;
  122. regfacet(unsigned int i = 0);
  123. jm_uintfast32_t RE_CALL lookup_classname(const wchar_t* first, const wchar_t* last)const { return do_lookup_classname(first, last); }
  124. bool RE_CALL lookup_collatename(re_str<wchar_t>& s, const re_str<wchar_t>& name)const { return do_lookup_collatename(s, name); }
  125. unsigned int RE_CALL syntax_type(wchar_t c)const { return do_syntax_type(c); }
  126. void RE_CALL update(const __JM_STD::locale& l)const { const_cast<regfacet<wchar_t>*>(this)->do_update(l); }
  127. wchar_t RE_CALL zero()const { return _zero; }
  128. wchar_t RE_CALL ten()const { return _ten; }
  129. protected:
  130. virtual jm_uintfast32_t RE_CALL do_lookup_classname(const wchar_t* first, const wchar_t* last)const;
  131. virtual bool RE_CALL do_lookup_collatename(re_str<wchar_t>& s, const re_str<wchar_t>& name)const;
  132. virtual unsigned int RE_CALL do_syntax_type(wchar_t)const;
  133. virtual void RE_CALL do_update(const __JM_STD::locale&);
  134. // required by Rogue Wave, not part of standard:
  135. __JM_STD::locale::id& get_id()const { return id; }
  136. ~regfacet();
  137. };
  138. JM_END_NAMESPACE
  139. #endif
  140. #endif