诸暨麻将添加redis
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

175 Zeilen
7.8 KiB

  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Author: kenton@google.com (Kenton Varda)
  31. // from google3/strings/substitute.h
  32. #include <string>
  33. #include <google/protobuf/stubs/common.h>
  34. #include <google/protobuf/stubs/strutil.h>
  35. #ifndef GOOGLE_PROTOBUF_STUBS_SUBSTITUTE_H_
  36. #define GOOGLE_PROTOBUF_STUBS_SUBSTITUTE_H_
  37. #include <google/protobuf/port_def.inc>
  38. namespace google {
  39. namespace protobuf {
  40. namespace strings {
  41. // ----------------------------------------------------------------------
  42. // strings::Substitute()
  43. // strings::SubstituteAndAppend()
  44. // Kind of like StringPrintf, but different.
  45. //
  46. // Example:
  47. // string GetMessage(string first_name, string last_name, int age) {
  48. // return strings::Substitute("My name is $0 $1 and I am $2 years old.",
  49. // first_name, last_name, age);
  50. // }
  51. //
  52. // Differences from StringPrintf:
  53. // * The format string does not identify the types of arguments.
  54. // Instead, the magic of C++ deals with this for us. See below
  55. // for a list of accepted types.
  56. // * Substitutions in the format string are identified by a '$'
  57. // followed by a digit. So, you can use arguments out-of-order and
  58. // use the same argument multiple times.
  59. // * It's much faster than StringPrintf.
  60. //
  61. // Supported types:
  62. // * Strings (const char*, const string&)
  63. // * Note that this means you do not have to add .c_str() to all of
  64. // your strings. In fact, you shouldn't; it will be slower.
  65. // * int32, int64, uint32, uint64: Formatted using SimpleItoa().
  66. // * float, double: Formatted using SimpleFtoa() and SimpleDtoa().
  67. // * bool: Printed as "true" or "false".
  68. //
  69. // SubstituteAndAppend() is like Substitute() but appends the result to
  70. // *output. Example:
  71. //
  72. // string str;
  73. // strings::SubstituteAndAppend(&str,
  74. // "My name is $0 $1 and I am $2 years old.",
  75. // first_name, last_name, age);
  76. //
  77. // Substitute() is significantly faster than StringPrintf(). For very
  78. // large strings, it may be orders of magnitude faster.
  79. // ----------------------------------------------------------------------
  80. namespace internal { // Implementation details.
  81. class SubstituteArg {
  82. public:
  83. inline SubstituteArg(const char* value)
  84. : text_(value), size_(strlen(text_)) {}
  85. inline SubstituteArg(const string& value)
  86. : text_(value.data()), size_(value.size()) {}
  87. // Indicates that no argument was given.
  88. inline explicit SubstituteArg()
  89. : text_(nullptr), size_(-1) {}
  90. // Primitives
  91. // We don't overload for signed and unsigned char because if people are
  92. // explicitly declaring their chars as signed or unsigned then they are
  93. // probably actually using them as 8-bit integers and would probably
  94. // prefer an integer representation. But, we don't really know. So, we
  95. // make the caller decide what to do.
  96. inline SubstituteArg(char value)
  97. : text_(scratch_), size_(1) { scratch_[0] = value; }
  98. inline SubstituteArg(short value)
  99. : text_(FastInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {}
  100. inline SubstituteArg(unsigned short value)
  101. : text_(FastUInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {}
  102. inline SubstituteArg(int value)
  103. : text_(FastInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {}
  104. inline SubstituteArg(unsigned int value)
  105. : text_(FastUInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {}
  106. inline SubstituteArg(long value)
  107. : text_(FastLongToBuffer(value, scratch_)), size_(strlen(text_)) {}
  108. inline SubstituteArg(unsigned long value)
  109. : text_(FastULongToBuffer(value, scratch_)), size_(strlen(text_)) {}
  110. inline SubstituteArg(long long value)
  111. : text_(FastInt64ToBuffer(value, scratch_)), size_(strlen(text_)) {}
  112. inline SubstituteArg(unsigned long long value)
  113. : text_(FastUInt64ToBuffer(value, scratch_)), size_(strlen(text_)) {}
  114. inline SubstituteArg(float value)
  115. : text_(FloatToBuffer(value, scratch_)), size_(strlen(text_)) {}
  116. inline SubstituteArg(double value)
  117. : text_(DoubleToBuffer(value, scratch_)), size_(strlen(text_)) {}
  118. inline SubstituteArg(bool value)
  119. : text_(value ? "true" : "false"), size_(strlen(text_)) {}
  120. inline const char* data() const { return text_; }
  121. inline int size() const { return size_; }
  122. private:
  123. const char* text_;
  124. int size_;
  125. char scratch_[kFastToBufferSize];
  126. };
  127. } // namespace internal
  128. PROTOBUF_EXPORT string
  129. Substitute(const char* format,
  130. const internal::SubstituteArg& arg0 = internal::SubstituteArg(),
  131. const internal::SubstituteArg& arg1 = internal::SubstituteArg(),
  132. const internal::SubstituteArg& arg2 = internal::SubstituteArg(),
  133. const internal::SubstituteArg& arg3 = internal::SubstituteArg(),
  134. const internal::SubstituteArg& arg4 = internal::SubstituteArg(),
  135. const internal::SubstituteArg& arg5 = internal::SubstituteArg(),
  136. const internal::SubstituteArg& arg6 = internal::SubstituteArg(),
  137. const internal::SubstituteArg& arg7 = internal::SubstituteArg(),
  138. const internal::SubstituteArg& arg8 = internal::SubstituteArg(),
  139. const internal::SubstituteArg& arg9 = internal::SubstituteArg());
  140. PROTOBUF_EXPORT void SubstituteAndAppend(
  141. string* output, const char* format,
  142. const internal::SubstituteArg& arg0 = internal::SubstituteArg(),
  143. const internal::SubstituteArg& arg1 = internal::SubstituteArg(),
  144. const internal::SubstituteArg& arg2 = internal::SubstituteArg(),
  145. const internal::SubstituteArg& arg3 = internal::SubstituteArg(),
  146. const internal::SubstituteArg& arg4 = internal::SubstituteArg(),
  147. const internal::SubstituteArg& arg5 = internal::SubstituteArg(),
  148. const internal::SubstituteArg& arg6 = internal::SubstituteArg(),
  149. const internal::SubstituteArg& arg7 = internal::SubstituteArg(),
  150. const internal::SubstituteArg& arg8 = internal::SubstituteArg(),
  151. const internal::SubstituteArg& arg9 = internal::SubstituteArg());
  152. } // namespace strings
  153. } // namespace protobuf
  154. } // namespace google
  155. #include <google/protobuf/port_undef.inc>
  156. #endif // GOOGLE_PROTOBUF_STUBS_SUBSTITUTE_H_