protoc 2.6.1.1 → 2.6.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (479) hide show
  1. checksums.yaml +4 -4
  2. data/ext/protoc/Makefile.in +10 -13
  3. data/ext/protoc/extconf.rb +0 -1
  4. data/ext/protoc/protobuf/CHANGES.txt +593 -0
  5. data/ext/protoc/protobuf/CONTRIBUTORS.txt +93 -0
  6. data/ext/protoc/protobuf/INSTALL.txt +237 -0
  7. data/ext/protoc/protobuf/LICENSE +33 -0
  8. data/ext/protoc/protobuf/Makefile.am +267 -0
  9. data/ext/protoc/protobuf/README.md +167 -0
  10. data/ext/protoc/protobuf/autogen.sh +41 -0
  11. data/ext/protoc/protobuf/benchmarks/ProtoBench.java +203 -0
  12. data/ext/protoc/protobuf/benchmarks/google_message1.dat +0 -0
  13. data/ext/protoc/protobuf/benchmarks/google_message2.dat +0 -0
  14. data/ext/protoc/protobuf/benchmarks/google_size.proto +136 -0
  15. data/ext/protoc/protobuf/benchmarks/google_speed.proto +136 -0
  16. data/ext/protoc/protobuf/benchmarks/readme.txt +50 -0
  17. data/ext/protoc/protobuf/configure.ac +159 -0
  18. data/ext/protoc/protobuf/editors/README.txt +5 -0
  19. data/ext/protoc/protobuf/editors/proto.vim +105 -0
  20. data/ext/protoc/protobuf/editors/protobuf-mode.el +220 -0
  21. data/ext/protoc/protobuf/examples/AddPerson.java +95 -0
  22. data/ext/protoc/protobuf/examples/ListPeople.java +50 -0
  23. data/ext/protoc/protobuf/examples/Makefile +58 -0
  24. data/ext/protoc/protobuf/examples/README.txt +29 -0
  25. data/ext/protoc/protobuf/examples/add_person.cc +95 -0
  26. data/ext/protoc/protobuf/examples/add_person.py +58 -0
  27. data/ext/protoc/protobuf/examples/addressbook.proto +30 -0
  28. data/ext/protoc/protobuf/examples/list_people.cc +68 -0
  29. data/ext/protoc/protobuf/examples/list_people.py +38 -0
  30. data/ext/protoc/protobuf/generate_descriptor_proto.sh +33 -0
  31. data/ext/protoc/protobuf/java/README.txt +96 -0
  32. data/ext/protoc/protobuf/java/pom.xml +217 -0
  33. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractMessage.java +466 -0
  34. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractMessageLite.java +355 -0
  35. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractParser.java +253 -0
  36. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BlockingRpcChannel.java +51 -0
  37. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BlockingService.java +64 -0
  38. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BoundedByteString.java +163 -0
  39. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ByteString.java +1022 -0
  40. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/CodedInputStream.java +1311 -0
  41. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/CodedOutputStream.java +1297 -0
  42. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Descriptors.java +2238 -0
  43. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/DynamicMessage.java +622 -0
  44. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Extension.java +96 -0
  45. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ExtensionRegistry.java +392 -0
  46. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ExtensionRegistryLite.java +185 -0
  47. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/FieldSet.java +907 -0
  48. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessage.java +2213 -0
  49. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java +949 -0
  50. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Internal.java +391 -0
  51. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java +122 -0
  52. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyField.java +154 -0
  53. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyFieldLite.java +176 -0
  54. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyStringArrayList.java +367 -0
  55. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyStringList.java +163 -0
  56. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LiteralByteString.java +362 -0
  57. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Message.java +244 -0
  58. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageLite.java +320 -0
  59. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java +60 -0
  60. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageOrBuilder.java +143 -0
  61. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageReflection.java +931 -0
  62. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Parser.java +261 -0
  63. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ProtocolMessageEnum.java +58 -0
  64. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ProtocolStringList.java +48 -0
  65. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java +696 -0
  66. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RopeByteString.java +957 -0
  67. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcCallback.java +47 -0
  68. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcChannel.java +71 -0
  69. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcController.java +118 -0
  70. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcUtil.java +134 -0
  71. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Service.java +117 -0
  72. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ServiceException.java +52 -0
  73. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/SingleFieldBuilder.java +241 -0
  74. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/SmallSortedMap.java +618 -0
  75. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/TextFormat.java +1984 -0
  76. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UninitializedMessageException.java +99 -0
  77. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UnknownFieldSet.java +995 -0
  78. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java +205 -0
  79. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Utf8.java +349 -0
  80. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/WireFormat.java +163 -0
  81. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/AbstractMessageTest.java +527 -0
  82. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/BoundedByteStringTest.java +68 -0
  83. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ByteStringTest.java +759 -0
  84. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CheckUtf8Test.java +141 -0
  85. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CodedInputStreamTest.java +769 -0
  86. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java +401 -0
  87. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DeprecatedFieldTest.java +80 -0
  88. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DescriptorsTest.java +735 -0
  89. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DynamicMessageTest.java +326 -0
  90. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java +48 -0
  91. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/GeneratedMessageTest.java +1515 -0
  92. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/IsValidUtf8Test.java +180 -0
  93. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java +421 -0
  94. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyFieldLiteTest.java +134 -0
  95. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyFieldTest.java +121 -0
  96. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyMessageLiteTest.java +319 -0
  97. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyStringArrayListTest.java +174 -0
  98. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java +143 -0
  99. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java +85 -0
  100. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteTest.java +148 -0
  101. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteralByteStringTest.java +396 -0
  102. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/MessageTest.java +353 -0
  103. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/NestedBuildersTest.java +185 -0
  104. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ParserTest.java +381 -0
  105. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java +190 -0
  106. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java +97 -0
  107. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RopeByteStringTest.java +115 -0
  108. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ServiceTest.java +320 -0
  109. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java +155 -0
  110. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/SmallSortedMapTest.java +420 -0
  111. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TestBadIdentifiers.java +96 -0
  112. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TestUtil.java +4124 -0
  113. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TextFormatTest.java +994 -0
  114. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/UnknownFieldSetTest.java +653 -0
  115. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java +227 -0
  116. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/WireFormatTest.java +606 -0
  117. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/lazy_fields_lite.proto +61 -0
  118. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/lite_equals_and_hash.proto +55 -0
  119. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/multiple_files_test.proto +77 -0
  120. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_builders_test.proto +53 -0
  121. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_extension.proto +46 -0
  122. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_extension_lite.proto +48 -0
  123. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/non_nested_extension.proto +49 -0
  124. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/non_nested_extension_lite.proto +50 -0
  125. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test.proto +38 -0
  126. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test2.proto +42 -0
  127. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test3.proto +43 -0
  128. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_bad_identifiers.proto +157 -0
  129. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_check_utf8.proto +50 -0
  130. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_check_utf8_size.proto +51 -0
  131. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_custom_options.proto +43 -0
  132. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_extra_interfaces.proto +60 -0
  133. data/ext/protoc/protobuf/m4/ac_system_extensions.m4 +37 -0
  134. data/ext/protoc/protobuf/m4/acx_check_suncc.m4 +75 -0
  135. data/ext/protoc/protobuf/m4/acx_pthread.m4 +397 -0
  136. data/ext/protoc/protobuf/m4/stl_hash.m4 +72 -0
  137. data/ext/protoc/protobuf/more_tests/Makefile +41 -0
  138. data/ext/protoc/protobuf/post_process_dist.sh +60 -0
  139. data/ext/protoc/protobuf/protobuf-lite.pc.in +13 -0
  140. data/ext/protoc/protobuf/protobuf.pc.in +14 -0
  141. data/ext/protoc/protobuf/python/README.txt +105 -0
  142. data/ext/protoc/protobuf/python/ez_setup.py +284 -0
  143. data/ext/protoc/protobuf/python/google/__init__.py +1 -0
  144. data/ext/protoc/protobuf/python/google/protobuf/__init__.py +0 -0
  145. data/ext/protoc/protobuf/python/google/protobuf/descriptor.py +849 -0
  146. data/ext/protoc/protobuf/python/google/protobuf/descriptor_database.py +137 -0
  147. data/ext/protoc/protobuf/python/google/protobuf/descriptor_pool.py +643 -0
  148. data/ext/protoc/protobuf/python/google/protobuf/internal/__init__.py +0 -0
  149. data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation.cc +139 -0
  150. data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation.py +89 -0
  151. data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation_default_test.py +63 -0
  152. data/ext/protoc/protobuf/python/google/protobuf/internal/containers.py +269 -0
  153. data/ext/protoc/protobuf/python/google/protobuf/internal/cpp_message.py +663 -0
  154. data/ext/protoc/protobuf/python/google/protobuf/internal/decoder.py +831 -0
  155. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_database_test.py +63 -0
  156. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test.py +564 -0
  157. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test1.proto +94 -0
  158. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test2.proto +70 -0
  159. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_python_test.py +54 -0
  160. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_test.py +669 -0
  161. data/ext/protoc/protobuf/python/google/protobuf/internal/encoder.py +788 -0
  162. data/ext/protoc/protobuf/python/google/protobuf/internal/enum_type_wrapper.py +89 -0
  163. data/ext/protoc/protobuf/python/google/protobuf/internal/factory_test1.proto +57 -0
  164. data/ext/protoc/protobuf/python/google/protobuf/internal/factory_test2.proto +92 -0
  165. data/ext/protoc/protobuf/python/google/protobuf/internal/generator_test.py +343 -0
  166. data/ext/protoc/protobuf/python/google/protobuf/internal/message_factory_python_test.py +54 -0
  167. data/ext/protoc/protobuf/python/google/protobuf/internal/message_factory_test.py +131 -0
  168. data/ext/protoc/protobuf/python/google/protobuf/internal/message_listener.py +78 -0
  169. data/ext/protoc/protobuf/python/google/protobuf/internal/message_python_test.py +54 -0
  170. data/ext/protoc/protobuf/python/google/protobuf/internal/message_test.py +681 -0
  171. data/ext/protoc/protobuf/python/google/protobuf/internal/missing_enum_values.proto +50 -0
  172. data/ext/protoc/protobuf/python/google/protobuf/internal/more_extensions.proto +58 -0
  173. data/ext/protoc/protobuf/python/google/protobuf/internal/more_extensions_dynamic.proto +49 -0
  174. data/ext/protoc/protobuf/python/google/protobuf/internal/more_messages.proto +51 -0
  175. data/ext/protoc/protobuf/python/google/protobuf/internal/python_message.py +1251 -0
  176. data/ext/protoc/protobuf/python/google/protobuf/internal/reflection_test.py +2934 -0
  177. data/ext/protoc/protobuf/python/google/protobuf/internal/service_reflection_test.py +136 -0
  178. data/ext/protoc/protobuf/python/google/protobuf/internal/symbol_database_test.py +120 -0
  179. data/ext/protoc/protobuf/python/google/protobuf/internal/test_bad_identifiers.proto +52 -0
  180. data/ext/protoc/protobuf/python/google/protobuf/internal/test_util.py +662 -0
  181. data/ext/protoc/protobuf/python/google/protobuf/internal/text_encoding_test.py +68 -0
  182. data/ext/protoc/protobuf/python/google/protobuf/internal/text_format_test.py +743 -0
  183. data/ext/protoc/protobuf/python/google/protobuf/internal/type_checkers.py +328 -0
  184. data/ext/protoc/protobuf/python/google/protobuf/internal/unknown_fields_test.py +231 -0
  185. data/ext/protoc/protobuf/python/google/protobuf/internal/wire_format.py +268 -0
  186. data/ext/protoc/protobuf/python/google/protobuf/internal/wire_format_test.py +253 -0
  187. data/ext/protoc/protobuf/python/google/protobuf/message.py +284 -0
  188. data/ext/protoc/protobuf/python/google/protobuf/message_factory.py +155 -0
  189. data/ext/protoc/protobuf/python/google/protobuf/pyext/README +6 -0
  190. data/ext/protoc/protobuf/python/google/protobuf/pyext/__init__.py +0 -0
  191. data/ext/protoc/protobuf/python/google/protobuf/pyext/cpp_message.py +61 -0
  192. data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor.cc +357 -0
  193. data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor.h +96 -0
  194. data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor_cpp2_test.py +58 -0
  195. data/ext/protoc/protobuf/python/google/protobuf/pyext/extension_dict.cc +338 -0
  196. data/ext/protoc/protobuf/python/google/protobuf/pyext/extension_dict.h +123 -0
  197. data/ext/protoc/protobuf/python/google/protobuf/pyext/message.cc +2561 -0
  198. data/ext/protoc/protobuf/python/google/protobuf/pyext/message.h +305 -0
  199. data/ext/protoc/protobuf/python/google/protobuf/pyext/message_factory_cpp2_test.py +56 -0
  200. data/ext/protoc/protobuf/python/google/protobuf/pyext/proto2_api_test.proto +38 -0
  201. data/ext/protoc/protobuf/python/google/protobuf/pyext/python.proto +66 -0
  202. data/ext/protoc/protobuf/python/google/protobuf/pyext/python_protobuf.h +57 -0
  203. data/ext/protoc/protobuf/python/google/protobuf/pyext/reflection_cpp2_generated_test.py +94 -0
  204. data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc +763 -0
  205. data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_composite_container.h +172 -0
  206. data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc +825 -0
  207. data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h +112 -0
  208. data/ext/protoc/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h +95 -0
  209. data/ext/protoc/protobuf/python/google/protobuf/reflection.py +205 -0
  210. data/ext/protoc/protobuf/python/google/protobuf/service.py +226 -0
  211. data/ext/protoc/protobuf/python/google/protobuf/service_reflection.py +284 -0
  212. data/ext/protoc/protobuf/python/google/protobuf/symbol_database.py +185 -0
  213. data/ext/protoc/protobuf/python/google/protobuf/text_encoding.py +110 -0
  214. data/ext/protoc/protobuf/python/google/protobuf/text_format.py +873 -0
  215. data/ext/protoc/protobuf/python/mox.py +1401 -0
  216. data/ext/protoc/protobuf/python/setup.py +201 -0
  217. data/ext/protoc/protobuf/python/stubout.py +140 -0
  218. data/ext/protoc/protobuf/src/Makefile.am +418 -0
  219. data/ext/protoc/protobuf/src/google/protobuf/SEBS +240 -0
  220. data/ext/protoc/protobuf/src/google/protobuf/compiler/code_generator.cc +84 -0
  221. data/ext/protoc/protobuf/src/google/protobuf/compiler/code_generator.h +145 -0
  222. data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface.cc +1603 -0
  223. data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface.h +378 -0
  224. data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc +1654 -0
  225. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc +158 -0
  226. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.cc +288 -0
  227. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.h +103 -0
  228. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc +431 -0
  229. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.h +122 -0
  230. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.cc +210 -0
  231. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.h +86 -0
  232. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc +166 -0
  233. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_field.h +185 -0
  234. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_file.cc +665 -0
  235. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_file.h +99 -0
  236. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.cc +125 -0
  237. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
  238. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.cc +494 -0
  239. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.h +206 -0
  240. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message.cc +2645 -0
  241. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message.h +175 -0
  242. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.cc +375 -0
  243. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.h +121 -0
  244. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_options.h +58 -0
  245. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc +123 -0
  246. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +451 -0
  247. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +123 -0
  248. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_service.cc +334 -0
  249. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
  250. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.cc +642 -0
  251. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.h +127 -0
  252. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto +132 -0
  253. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.cc +2074 -0
  254. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.h +51 -0
  255. data/ext/protoc/protobuf/src/google/protobuf/compiler/importer.cc +480 -0
  256. data/ext/protoc/protobuf/src/google/protobuf/compiler/importer.h +317 -0
  257. data/ext/protoc/protobuf/src/google/protobuf/compiler/importer_unittest.cc +617 -0
  258. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_context.cc +195 -0
  259. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_context.h +95 -0
  260. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment.cc +233 -0
  261. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment.h +69 -0
  262. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc +67 -0
  263. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum.cc +333 -0
  264. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum.h +99 -0
  265. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum_field.cc +778 -0
  266. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum_field.h +158 -0
  267. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_extension.cc +207 -0
  268. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_extension.h +109 -0
  269. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_field.cc +213 -0
  270. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_field.h +162 -0
  271. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_file.cc +534 -0
  272. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_file.h +115 -0
  273. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator.cc +158 -0
  274. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator.h +72 -0
  275. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator_factory.cc +77 -0
  276. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator_factory.h +101 -0
  277. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_helpers.cc +737 -0
  278. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_helpers.h +322 -0
  279. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.cc +826 -0
  280. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.h +121 -0
  281. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message.cc +1666 -0
  282. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message.h +140 -0
  283. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message_field.cc +1343 -0
  284. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message_field.h +173 -0
  285. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_name_resolver.cc +266 -0
  286. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_name_resolver.h +124 -0
  287. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_plugin_unittest.cc +124 -0
  288. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_primitive_field.cc +877 -0
  289. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_primitive_field.h +160 -0
  290. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_service.cc +473 -0
  291. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_service.h +135 -0
  292. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.cc +201 -0
  293. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.h +90 -0
  294. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_string_field.cc +1056 -0
  295. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_string_field.h +160 -0
  296. data/ext/protoc/protobuf/src/google/protobuf/compiler/main.cc +61 -0
  297. data/ext/protoc/protobuf/src/google/protobuf/compiler/mock_code_generator.cc +240 -0
  298. data/ext/protoc/protobuf/src/google/protobuf/compiler/mock_code_generator.h +117 -0
  299. data/ext/protoc/protobuf/src/google/protobuf/compiler/package_info.h +64 -0
  300. data/ext/protoc/protobuf/src/google/protobuf/compiler/parser.cc +1750 -0
  301. data/ext/protoc/protobuf/src/google/protobuf/compiler/parser.h +522 -0
  302. data/ext/protoc/protobuf/src/google/protobuf/compiler/parser_unittest.cc +2612 -0
  303. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.cc +163 -0
  304. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.h +72 -0
  305. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.pb.cc +1148 -0
  306. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.pb.h +897 -0
  307. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.proto +147 -0
  308. data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_generator.cc +1262 -0
  309. data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_generator.h +166 -0
  310. data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_plugin_unittest.cc +118 -0
  311. data/ext/protoc/protobuf/src/google/protobuf/compiler/subprocess.cc +463 -0
  312. data/ext/protoc/protobuf/src/google/protobuf/compiler/subprocess.h +108 -0
  313. data/ext/protoc/protobuf/src/google/protobuf/compiler/test_plugin.cc +51 -0
  314. data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_output_unittest.sh +91 -0
  315. data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_writer.cc +218 -0
  316. data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_writer.h +93 -0
  317. data/ext/protoc/protobuf/src/google/protobuf/descriptor.cc +5420 -0
  318. data/ext/protoc/protobuf/src/google/protobuf/descriptor.h +1691 -0
  319. data/ext/protoc/protobuf/src/google/protobuf/descriptor.pb.cc +9135 -0
  320. data/ext/protoc/protobuf/src/google/protobuf/descriptor.pb.h +6761 -0
  321. data/ext/protoc/protobuf/src/google/protobuf/descriptor.proto +687 -0
  322. data/ext/protoc/protobuf/src/google/protobuf/descriptor_database.cc +543 -0
  323. data/ext/protoc/protobuf/src/google/protobuf/descriptor_database.h +369 -0
  324. data/ext/protoc/protobuf/src/google/protobuf/descriptor_database_unittest.cc +748 -0
  325. data/ext/protoc/protobuf/src/google/protobuf/descriptor_pb2_test.py +54 -0
  326. data/ext/protoc/protobuf/src/google/protobuf/descriptor_unittest.cc +5501 -0
  327. data/ext/protoc/protobuf/src/google/protobuf/dynamic_message.cc +764 -0
  328. data/ext/protoc/protobuf/src/google/protobuf/dynamic_message.h +148 -0
  329. data/ext/protoc/protobuf/src/google/protobuf/dynamic_message_unittest.cc +230 -0
  330. data/ext/protoc/protobuf/src/google/protobuf/extension_set.cc +1663 -0
  331. data/ext/protoc/protobuf/src/google/protobuf/extension_set.h +1234 -0
  332. data/ext/protoc/protobuf/src/google/protobuf/extension_set_heavy.cc +734 -0
  333. data/ext/protoc/protobuf/src/google/protobuf/extension_set_unittest.cc +1095 -0
  334. data/ext/protoc/protobuf/src/google/protobuf/generated_enum_reflection.h +91 -0
  335. data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection.cc +1683 -0
  336. data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection.h +504 -0
  337. data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc +795 -0
  338. data/ext/protoc/protobuf/src/google/protobuf/generated_message_util.cc +65 -0
  339. data/ext/protoc/protobuf/src/google/protobuf/generated_message_util.h +113 -0
  340. data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream.cc +914 -0
  341. data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream.h +1220 -0
  342. data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream_inl.h +69 -0
  343. data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream_unittest.cc +1378 -0
  344. data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream.cc +326 -0
  345. data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream.h +209 -0
  346. data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream_unittest.sh +44 -0
  347. data/ext/protoc/protobuf/src/google/protobuf/io/package_info.h +54 -0
  348. data/ext/protoc/protobuf/src/google/protobuf/io/printer.cc +198 -0
  349. data/ext/protoc/protobuf/src/google/protobuf/io/printer.h +136 -0
  350. data/ext/protoc/protobuf/src/google/protobuf/io/printer_unittest.cc +285 -0
  351. data/ext/protoc/protobuf/src/google/protobuf/io/strtod.cc +113 -0
  352. data/ext/protoc/protobuf/src/google/protobuf/io/strtod.h +50 -0
  353. data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer.cc +1127 -0
  354. data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer.h +402 -0
  355. data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer_unittest.cc +999 -0
  356. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream.cc +57 -0
  357. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream.h +248 -0
  358. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc +473 -0
  359. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h +358 -0
  360. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc +405 -0
  361. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h +354 -0
  362. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc +965 -0
  363. data/ext/protoc/protobuf/src/google/protobuf/lite_unittest.cc +350 -0
  364. data/ext/protoc/protobuf/src/google/protobuf/message.cc +358 -0
  365. data/ext/protoc/protobuf/src/google/protobuf/message.h +866 -0
  366. data/ext/protoc/protobuf/src/google/protobuf/message_lite.cc +335 -0
  367. data/ext/protoc/protobuf/src/google/protobuf/message_lite.h +247 -0
  368. data/ext/protoc/protobuf/src/google/protobuf/message_unittest.cc +427 -0
  369. data/ext/protoc/protobuf/src/google/protobuf/package_info.h +64 -0
  370. data/ext/protoc/protobuf/src/google/protobuf/reflection_ops.cc +269 -0
  371. data/ext/protoc/protobuf/src/google/protobuf/reflection_ops.h +81 -0
  372. data/ext/protoc/protobuf/src/google/protobuf/reflection_ops_unittest.cc +475 -0
  373. data/ext/protoc/protobuf/src/google/protobuf/repeated_field.cc +87 -0
  374. data/ext/protoc/protobuf/src/google/protobuf/repeated_field.h +1603 -0
  375. data/ext/protoc/protobuf/src/google/protobuf/repeated_field_reflection_unittest.cc +195 -0
  376. data/ext/protoc/protobuf/src/google/protobuf/repeated_field_unittest.cc +1442 -0
  377. data/ext/protoc/protobuf/src/google/protobuf/service.cc +46 -0
  378. data/ext/protoc/protobuf/src/google/protobuf/service.h +291 -0
  379. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops.h +227 -0
  380. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h +325 -0
  381. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h +151 -0
  382. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h +146 -0
  383. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h +122 -0
  384. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h +137 -0
  385. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_macosx.h +225 -0
  386. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h +313 -0
  387. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_pnacl.h +73 -0
  388. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_solaris.h +188 -0
  389. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_tsan.h +219 -0
  390. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc +137 -0
  391. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h +293 -0
  392. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc +112 -0
  393. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h +150 -0
  394. data/ext/protoc/protobuf/src/google/protobuf/stubs/common.cc +395 -0
  395. data/ext/protoc/protobuf/src/google/protobuf/stubs/common.h +1226 -0
  396. data/ext/protoc/protobuf/src/google/protobuf/stubs/common_unittest.cc +357 -0
  397. data/ext/protoc/protobuf/src/google/protobuf/stubs/hash.h +232 -0
  398. data/ext/protoc/protobuf/src/google/protobuf/stubs/map_util.h +771 -0
  399. data/ext/protoc/protobuf/src/google/protobuf/stubs/once.cc +99 -0
  400. data/ext/protoc/protobuf/src/google/protobuf/stubs/once.h +166 -0
  401. data/ext/protoc/protobuf/src/google/protobuf/stubs/once_unittest.cc +253 -0
  402. data/ext/protoc/protobuf/src/google/protobuf/stubs/platform_macros.h +103 -0
  403. data/ext/protoc/protobuf/src/google/protobuf/stubs/shared_ptr.h +470 -0
  404. data/ext/protoc/protobuf/src/google/protobuf/stubs/stl_util.h +121 -0
  405. data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf.cc +175 -0
  406. data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf.h +76 -0
  407. data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf_unittest.cc +152 -0
  408. data/ext/protoc/protobuf/src/google/protobuf/stubs/structurally_valid.cc +536 -0
  409. data/ext/protoc/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc +40 -0
  410. data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil.cc +1279 -0
  411. data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil.h +562 -0
  412. data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil_unittest.cc +73 -0
  413. data/ext/protoc/protobuf/src/google/protobuf/stubs/substitute.cc +134 -0
  414. data/ext/protoc/protobuf/src/google/protobuf/stubs/substitute.h +170 -0
  415. data/ext/protoc/protobuf/src/google/protobuf/stubs/template_util.h +138 -0
  416. data/ext/protoc/protobuf/src/google/protobuf/stubs/template_util_unittest.cc +130 -0
  417. data/ext/protoc/protobuf/src/google/protobuf/stubs/type_traits.h +336 -0
  418. data/ext/protoc/protobuf/src/google/protobuf/stubs/type_traits_unittest.cc +628 -0
  419. data/ext/protoc/protobuf/src/google/protobuf/test_util.cc +3345 -0
  420. data/ext/protoc/protobuf/src/google/protobuf/test_util.h +215 -0
  421. data/ext/protoc/protobuf/src/google/protobuf/test_util_lite.cc +1585 -0
  422. data/ext/protoc/protobuf/src/google/protobuf/test_util_lite.h +101 -0
  423. data/ext/protoc/protobuf/src/google/protobuf/testdata/bad_utf8_string +1 -0
  424. data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_message +0 -0
  425. data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_message_oneof_implemented +0 -0
  426. data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_packed_fields_message +0 -0
  427. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data.txt +134 -0
  428. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt +129 -0
  429. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy.txt +134 -0
  430. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt +129 -0
  431. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data.txt +134 -0
  432. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt +134 -0
  433. data/ext/protoc/protobuf/src/google/protobuf/testing/file.cc +194 -0
  434. data/ext/protoc/protobuf/src/google/protobuf/testing/file.h +97 -0
  435. data/ext/protoc/protobuf/src/google/protobuf/testing/googletest.cc +255 -0
  436. data/ext/protoc/protobuf/src/google/protobuf/testing/googletest.h +102 -0
  437. data/ext/protoc/protobuf/src/google/protobuf/testing/zcgunzip.cc +73 -0
  438. data/ext/protoc/protobuf/src/google/protobuf/testing/zcgzip.cc +79 -0
  439. data/ext/protoc/protobuf/src/google/protobuf/text_format.cc +1746 -0
  440. data/ext/protoc/protobuf/src/google/protobuf/text_format.h +473 -0
  441. data/ext/protoc/protobuf/src/google/protobuf/text_format_unittest.cc +1479 -0
  442. data/ext/protoc/protobuf/src/google/protobuf/unittest.proto +861 -0
  443. data/ext/protoc/protobuf/src/google/protobuf/unittest_custom_options.proto +393 -0
  444. data/ext/protoc/protobuf/src/google/protobuf/unittest_embed_optimize_for.proto +50 -0
  445. data/ext/protoc/protobuf/src/google/protobuf/unittest_empty.proto +37 -0
  446. data/ext/protoc/protobuf/src/google/protobuf/unittest_enormous_descriptor.proto +1046 -0
  447. data/ext/protoc/protobuf/src/google/protobuf/unittest_import.proto +64 -0
  448. data/ext/protoc/protobuf/src/google/protobuf/unittest_import_lite.proto +51 -0
  449. data/ext/protoc/protobuf/src/google/protobuf/unittest_import_public.proto +40 -0
  450. data/ext/protoc/protobuf/src/google/protobuf/unittest_import_public_lite.proto +42 -0
  451. data/ext/protoc/protobuf/src/google/protobuf/unittest_lite.proto +384 -0
  452. data/ext/protoc/protobuf/src/google/protobuf/unittest_lite_imports_nonlite.proto +43 -0
  453. data/ext/protoc/protobuf/src/google/protobuf/unittest_mset.proto +83 -0
  454. data/ext/protoc/protobuf/src/google/protobuf/unittest_no_generic_services.proto +53 -0
  455. data/ext/protoc/protobuf/src/google/protobuf/unittest_optimize_for.proto +66 -0
  456. data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set.cc +265 -0
  457. data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set.h +318 -0
  458. data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set_unittest.cc +599 -0
  459. data/ext/protoc/protobuf/src/google/protobuf/wire_format.cc +1101 -0
  460. data/ext/protoc/protobuf/src/google/protobuf/wire_format.h +336 -0
  461. data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite.cc +471 -0
  462. data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite.h +661 -0
  463. data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite_inl.h +860 -0
  464. data/ext/protoc/protobuf/src/google/protobuf/wire_format_unittest.cc +1120 -0
  465. data/ext/protoc/protobuf/src/solaris/libstdc++.la +51 -0
  466. data/ext/protoc/protobuf/vsprojects/config.h +29 -0
  467. data/ext/protoc/protobuf/vsprojects/convert2008to2005.sh +20 -0
  468. data/ext/protoc/protobuf/vsprojects/extract_includes.bat +50 -0
  469. data/ext/protoc/protobuf/vsprojects/libprotobuf-lite.vcproj +302 -0
  470. data/ext/protoc/protobuf/vsprojects/libprotobuf.vcproj +470 -0
  471. data/ext/protoc/protobuf/vsprojects/libprotoc.vcproj +466 -0
  472. data/ext/protoc/protobuf/vsprojects/lite-test.vcproj +305 -0
  473. data/ext/protoc/protobuf/vsprojects/protobuf.sln +92 -0
  474. data/ext/protoc/protobuf/vsprojects/protoc.vcproj +192 -0
  475. data/ext/protoc/protobuf/vsprojects/readme.txt +114 -0
  476. data/ext/protoc/protobuf/vsprojects/test_plugin.vcproj +209 -0
  477. data/ext/protoc/protobuf/vsprojects/tests.vcproj +681 -0
  478. data/lib/protoc/version.rb +1 -1
  479. metadata +480 -3
@@ -0,0 +1,40 @@
1
+ // Copyright 2008 Google Inc. All Rights Reserved.
2
+ // Author: xpeng@google.com (Peter Peng)
3
+
4
+ #include <google/protobuf/stubs/common.h>
5
+ #include <gtest/gtest.h>
6
+
7
+ namespace google {
8
+ namespace protobuf {
9
+ namespace internal {
10
+ namespace {
11
+
12
+ TEST(StructurallyValidTest, ValidUTF8String) {
13
+ // On GCC, this string can be written as:
14
+ // "abcd 1234 - \u2014\u2013\u2212"
15
+ // MSVC seems to interpret \u differently.
16
+ string valid_str("abcd 1234 - \342\200\224\342\200\223\342\210\222 - xyz789");
17
+ EXPECT_TRUE(IsStructurallyValidUTF8(valid_str.data(),
18
+ valid_str.size()));
19
+ // Additional check for pointer alignment
20
+ for (int i = 1; i < 8; ++i) {
21
+ EXPECT_TRUE(IsStructurallyValidUTF8(valid_str.data() + i,
22
+ valid_str.size() - i));
23
+ }
24
+ }
25
+
26
+ TEST(StructurallyValidTest, InvalidUTF8String) {
27
+ const string invalid_str("abcd\xA0\xB0\xA0\xB0\xA0\xB0 - xyz789");
28
+ EXPECT_FALSE(IsStructurallyValidUTF8(invalid_str.data(),
29
+ invalid_str.size()));
30
+ // Additional check for pointer alignment
31
+ for (int i = 1; i < 8; ++i) {
32
+ EXPECT_FALSE(IsStructurallyValidUTF8(invalid_str.data() + i,
33
+ invalid_str.size() - i));
34
+ }
35
+ }
36
+
37
+ } // namespace
38
+ } // namespace internal
39
+ } // namespace protobuf
40
+ } // namespace google
@@ -0,0 +1,1279 @@
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
+
31
+ // from google3/strings/strutil.cc
32
+
33
+ #include <google/protobuf/stubs/strutil.h>
34
+ #include <errno.h>
35
+ #include <float.h> // FLT_DIG and DBL_DIG
36
+ #include <limits>
37
+ #include <limits.h>
38
+ #include <stdio.h>
39
+ #include <iterator>
40
+
41
+ #ifdef _WIN32
42
+ // MSVC has only _snprintf, not snprintf.
43
+ //
44
+ // MinGW has both snprintf and _snprintf, but they appear to be different
45
+ // functions. The former is buggy. When invoked like so:
46
+ // char buffer[32];
47
+ // snprintf(buffer, 32, "%.*g\n", FLT_DIG, 1.23e10f);
48
+ // it prints "1.23000e+10". This is plainly wrong: %g should never print
49
+ // trailing zeros after the decimal point. For some reason this bug only
50
+ // occurs with some input values, not all. In any case, _snprintf does the
51
+ // right thing, so we use it.
52
+ #define snprintf _snprintf
53
+ #endif
54
+
55
+ namespace google {
56
+ namespace protobuf {
57
+
58
+ inline bool IsNaN(double value) {
59
+ // NaN is never equal to anything, even itself.
60
+ return value != value;
61
+ }
62
+
63
+ // These are defined as macros on some platforms. #undef them so that we can
64
+ // redefine them.
65
+ #undef isxdigit
66
+ #undef isprint
67
+
68
+ // The definitions of these in ctype.h change based on locale. Since our
69
+ // string manipulation is all in relation to the protocol buffer and C++
70
+ // languages, we always want to use the C locale. So, we re-define these
71
+ // exactly as we want them.
72
+ inline bool isxdigit(char c) {
73
+ return ('0' <= c && c <= '9') ||
74
+ ('a' <= c && c <= 'f') ||
75
+ ('A' <= c && c <= 'F');
76
+ }
77
+
78
+ inline bool isprint(char c) {
79
+ return c >= 0x20 && c <= 0x7E;
80
+ }
81
+
82
+ // ----------------------------------------------------------------------
83
+ // StripString
84
+ // Replaces any occurrence of the character 'remove' (or the characters
85
+ // in 'remove') with the character 'replacewith'.
86
+ // ----------------------------------------------------------------------
87
+ void StripString(string* s, const char* remove, char replacewith) {
88
+ const char * str_start = s->c_str();
89
+ const char * str = str_start;
90
+ for (str = strpbrk(str, remove);
91
+ str != NULL;
92
+ str = strpbrk(str + 1, remove)) {
93
+ (*s)[str - str_start] = replacewith;
94
+ }
95
+ }
96
+
97
+ // ----------------------------------------------------------------------
98
+ // StringReplace()
99
+ // Replace the "old" pattern with the "new" pattern in a string,
100
+ // and append the result to "res". If replace_all is false,
101
+ // it only replaces the first instance of "old."
102
+ // ----------------------------------------------------------------------
103
+
104
+ void StringReplace(const string& s, const string& oldsub,
105
+ const string& newsub, bool replace_all,
106
+ string* res) {
107
+ if (oldsub.empty()) {
108
+ res->append(s); // if empty, append the given string.
109
+ return;
110
+ }
111
+
112
+ string::size_type start_pos = 0;
113
+ string::size_type pos;
114
+ do {
115
+ pos = s.find(oldsub, start_pos);
116
+ if (pos == string::npos) {
117
+ break;
118
+ }
119
+ res->append(s, start_pos, pos - start_pos);
120
+ res->append(newsub);
121
+ start_pos = pos + oldsub.size(); // start searching again after the "old"
122
+ } while (replace_all);
123
+ res->append(s, start_pos, s.length() - start_pos);
124
+ }
125
+
126
+ // ----------------------------------------------------------------------
127
+ // StringReplace()
128
+ // Give me a string and two patterns "old" and "new", and I replace
129
+ // the first instance of "old" in the string with "new", if it
130
+ // exists. If "global" is true; call this repeatedly until it
131
+ // fails. RETURN a new string, regardless of whether the replacement
132
+ // happened or not.
133
+ // ----------------------------------------------------------------------
134
+
135
+ string StringReplace(const string& s, const string& oldsub,
136
+ const string& newsub, bool replace_all) {
137
+ string ret;
138
+ StringReplace(s, oldsub, newsub, replace_all, &ret);
139
+ return ret;
140
+ }
141
+
142
+ // ----------------------------------------------------------------------
143
+ // SplitStringUsing()
144
+ // Split a string using a character delimiter. Append the components
145
+ // to 'result'.
146
+ //
147
+ // Note: For multi-character delimiters, this routine will split on *ANY* of
148
+ // the characters in the string, not the entire string as a single delimiter.
149
+ // ----------------------------------------------------------------------
150
+ template <typename ITR>
151
+ static inline
152
+ void SplitStringToIteratorUsing(const string& full,
153
+ const char* delim,
154
+ ITR& result) {
155
+ // Optimize the common case where delim is a single character.
156
+ if (delim[0] != '\0' && delim[1] == '\0') {
157
+ char c = delim[0];
158
+ const char* p = full.data();
159
+ const char* end = p + full.size();
160
+ while (p != end) {
161
+ if (*p == c) {
162
+ ++p;
163
+ } else {
164
+ const char* start = p;
165
+ while (++p != end && *p != c);
166
+ *result++ = string(start, p - start);
167
+ }
168
+ }
169
+ return;
170
+ }
171
+
172
+ string::size_type begin_index, end_index;
173
+ begin_index = full.find_first_not_of(delim);
174
+ while (begin_index != string::npos) {
175
+ end_index = full.find_first_of(delim, begin_index);
176
+ if (end_index == string::npos) {
177
+ *result++ = full.substr(begin_index);
178
+ return;
179
+ }
180
+ *result++ = full.substr(begin_index, (end_index - begin_index));
181
+ begin_index = full.find_first_not_of(delim, end_index);
182
+ }
183
+ }
184
+
185
+ void SplitStringUsing(const string& full,
186
+ const char* delim,
187
+ vector<string>* result) {
188
+ back_insert_iterator< vector<string> > it(*result);
189
+ SplitStringToIteratorUsing(full, delim, it);
190
+ }
191
+
192
+ // Split a string using a character delimiter. Append the components
193
+ // to 'result'. If there are consecutive delimiters, this function
194
+ // will return corresponding empty strings. The string is split into
195
+ // at most the specified number of pieces greedily. This means that the
196
+ // last piece may possibly be split further. To split into as many pieces
197
+ // as possible, specify 0 as the number of pieces.
198
+ //
199
+ // If "full" is the empty string, yields an empty string as the only value.
200
+ //
201
+ // If "pieces" is negative for some reason, it returns the whole string
202
+ // ----------------------------------------------------------------------
203
+ template <typename StringType, typename ITR>
204
+ static inline
205
+ void SplitStringToIteratorAllowEmpty(const StringType& full,
206
+ const char* delim,
207
+ int pieces,
208
+ ITR& result) {
209
+ string::size_type begin_index, end_index;
210
+ begin_index = 0;
211
+
212
+ for (int i = 0; (i < pieces-1) || (pieces == 0); i++) {
213
+ end_index = full.find_first_of(delim, begin_index);
214
+ if (end_index == string::npos) {
215
+ *result++ = full.substr(begin_index);
216
+ return;
217
+ }
218
+ *result++ = full.substr(begin_index, (end_index - begin_index));
219
+ begin_index = end_index + 1;
220
+ }
221
+ *result++ = full.substr(begin_index);
222
+ }
223
+
224
+ void SplitStringAllowEmpty(const string& full, const char* delim,
225
+ vector<string>* result) {
226
+ back_insert_iterator<vector<string> > it(*result);
227
+ SplitStringToIteratorAllowEmpty(full, delim, 0, it);
228
+ }
229
+
230
+ // ----------------------------------------------------------------------
231
+ // JoinStrings()
232
+ // This merges a vector of string components with delim inserted
233
+ // as separaters between components.
234
+ //
235
+ // ----------------------------------------------------------------------
236
+ template <class ITERATOR>
237
+ static void JoinStringsIterator(const ITERATOR& start,
238
+ const ITERATOR& end,
239
+ const char* delim,
240
+ string* result) {
241
+ GOOGLE_CHECK(result != NULL);
242
+ result->clear();
243
+ int delim_length = strlen(delim);
244
+
245
+ // Precompute resulting length so we can reserve() memory in one shot.
246
+ int length = 0;
247
+ for (ITERATOR iter = start; iter != end; ++iter) {
248
+ if (iter != start) {
249
+ length += delim_length;
250
+ }
251
+ length += iter->size();
252
+ }
253
+ result->reserve(length);
254
+
255
+ // Now combine everything.
256
+ for (ITERATOR iter = start; iter != end; ++iter) {
257
+ if (iter != start) {
258
+ result->append(delim, delim_length);
259
+ }
260
+ result->append(iter->data(), iter->size());
261
+ }
262
+ }
263
+
264
+ void JoinStrings(const vector<string>& components,
265
+ const char* delim,
266
+ string * result) {
267
+ JoinStringsIterator(components.begin(), components.end(), delim, result);
268
+ }
269
+
270
+ // ----------------------------------------------------------------------
271
+ // UnescapeCEscapeSequences()
272
+ // This does all the unescaping that C does: \ooo, \r, \n, etc
273
+ // Returns length of resulting string.
274
+ // The implementation of \x parses any positive number of hex digits,
275
+ // but it is an error if the value requires more than 8 bits, and the
276
+ // result is truncated to 8 bits.
277
+ //
278
+ // The second call stores its errors in a supplied string vector.
279
+ // If the string vector pointer is NULL, it reports the errors with LOG().
280
+ // ----------------------------------------------------------------------
281
+
282
+ #define IS_OCTAL_DIGIT(c) (((c) >= '0') && ((c) <= '7'))
283
+
284
+ inline int hex_digit_to_int(char c) {
285
+ /* Assume ASCII. */
286
+ assert('0' == 0x30 && 'A' == 0x41 && 'a' == 0x61);
287
+ assert(isxdigit(c));
288
+ int x = static_cast<unsigned char>(c);
289
+ if (x > '9') {
290
+ x += 9;
291
+ }
292
+ return x & 0xf;
293
+ }
294
+
295
+ // Protocol buffers doesn't ever care about errors, but I don't want to remove
296
+ // the code.
297
+ #define LOG_STRING(LEVEL, VECTOR) GOOGLE_LOG_IF(LEVEL, false)
298
+
299
+ int UnescapeCEscapeSequences(const char* source, char* dest) {
300
+ return UnescapeCEscapeSequences(source, dest, NULL);
301
+ }
302
+
303
+ int UnescapeCEscapeSequences(const char* source, char* dest,
304
+ vector<string> *errors) {
305
+ GOOGLE_DCHECK(errors == NULL) << "Error reporting not implemented.";
306
+
307
+ char* d = dest;
308
+ const char* p = source;
309
+
310
+ // Small optimization for case where source = dest and there's no escaping
311
+ while ( p == d && *p != '\0' && *p != '\\' )
312
+ p++, d++;
313
+
314
+ while (*p != '\0') {
315
+ if (*p != '\\') {
316
+ *d++ = *p++;
317
+ } else {
318
+ switch ( *++p ) { // skip past the '\\'
319
+ case '\0':
320
+ LOG_STRING(ERROR, errors) << "String cannot end with \\";
321
+ *d = '\0';
322
+ return d - dest; // we're done with p
323
+ case 'a': *d++ = '\a'; break;
324
+ case 'b': *d++ = '\b'; break;
325
+ case 'f': *d++ = '\f'; break;
326
+ case 'n': *d++ = '\n'; break;
327
+ case 'r': *d++ = '\r'; break;
328
+ case 't': *d++ = '\t'; break;
329
+ case 'v': *d++ = '\v'; break;
330
+ case '\\': *d++ = '\\'; break;
331
+ case '?': *d++ = '\?'; break; // \? Who knew?
332
+ case '\'': *d++ = '\''; break;
333
+ case '"': *d++ = '\"'; break;
334
+ case '0': case '1': case '2': case '3': // octal digit: 1 to 3 digits
335
+ case '4': case '5': case '6': case '7': {
336
+ char ch = *p - '0';
337
+ if ( IS_OCTAL_DIGIT(p[1]) )
338
+ ch = ch * 8 + *++p - '0';
339
+ if ( IS_OCTAL_DIGIT(p[1]) ) // safe (and easy) to do this twice
340
+ ch = ch * 8 + *++p - '0'; // now points at last digit
341
+ *d++ = ch;
342
+ break;
343
+ }
344
+ case 'x': case 'X': {
345
+ if (!isxdigit(p[1])) {
346
+ if (p[1] == '\0') {
347
+ LOG_STRING(ERROR, errors) << "String cannot end with \\x";
348
+ } else {
349
+ LOG_STRING(ERROR, errors) <<
350
+ "\\x cannot be followed by non-hex digit: \\" << *p << p[1];
351
+ }
352
+ break;
353
+ }
354
+ unsigned int ch = 0;
355
+ const char *hex_start = p;
356
+ while (isxdigit(p[1])) // arbitrarily many hex digits
357
+ ch = (ch << 4) + hex_digit_to_int(*++p);
358
+ if (ch > 0xFF)
359
+ LOG_STRING(ERROR, errors) << "Value of " <<
360
+ "\\" << string(hex_start, p+1-hex_start) << " exceeds 8 bits";
361
+ *d++ = ch;
362
+ break;
363
+ }
364
+ #if 0 // TODO(kenton): Support \u and \U? Requires runetochar().
365
+ case 'u': {
366
+ // \uhhhh => convert 4 hex digits to UTF-8
367
+ char32 rune = 0;
368
+ const char *hex_start = p;
369
+ for (int i = 0; i < 4; ++i) {
370
+ if (isxdigit(p[1])) { // Look one char ahead.
371
+ rune = (rune << 4) + hex_digit_to_int(*++p); // Advance p.
372
+ } else {
373
+ LOG_STRING(ERROR, errors)
374
+ << "\\u must be followed by 4 hex digits: \\"
375
+ << string(hex_start, p+1-hex_start);
376
+ break;
377
+ }
378
+ }
379
+ d += runetochar(d, &rune);
380
+ break;
381
+ }
382
+ case 'U': {
383
+ // \Uhhhhhhhh => convert 8 hex digits to UTF-8
384
+ char32 rune = 0;
385
+ const char *hex_start = p;
386
+ for (int i = 0; i < 8; ++i) {
387
+ if (isxdigit(p[1])) { // Look one char ahead.
388
+ // Don't change rune until we're sure this
389
+ // is within the Unicode limit, but do advance p.
390
+ char32 newrune = (rune << 4) + hex_digit_to_int(*++p);
391
+ if (newrune > 0x10FFFF) {
392
+ LOG_STRING(ERROR, errors)
393
+ << "Value of \\"
394
+ << string(hex_start, p + 1 - hex_start)
395
+ << " exceeds Unicode limit (0x10FFFF)";
396
+ break;
397
+ } else {
398
+ rune = newrune;
399
+ }
400
+ } else {
401
+ LOG_STRING(ERROR, errors)
402
+ << "\\U must be followed by 8 hex digits: \\"
403
+ << string(hex_start, p+1-hex_start);
404
+ break;
405
+ }
406
+ }
407
+ d += runetochar(d, &rune);
408
+ break;
409
+ }
410
+ #endif
411
+ default:
412
+ LOG_STRING(ERROR, errors) << "Unknown escape sequence: \\" << *p;
413
+ }
414
+ p++; // read past letter we escaped
415
+ }
416
+ }
417
+ *d = '\0';
418
+ return d - dest;
419
+ }
420
+
421
+ // ----------------------------------------------------------------------
422
+ // UnescapeCEscapeString()
423
+ // This does the same thing as UnescapeCEscapeSequences, but creates
424
+ // a new string. The caller does not need to worry about allocating
425
+ // a dest buffer. This should be used for non performance critical
426
+ // tasks such as printing debug messages. It is safe for src and dest
427
+ // to be the same.
428
+ //
429
+ // The second call stores its errors in a supplied string vector.
430
+ // If the string vector pointer is NULL, it reports the errors with LOG().
431
+ //
432
+ // In the first and second calls, the length of dest is returned. In the
433
+ // the third call, the new string is returned.
434
+ // ----------------------------------------------------------------------
435
+ int UnescapeCEscapeString(const string& src, string* dest) {
436
+ return UnescapeCEscapeString(src, dest, NULL);
437
+ }
438
+
439
+ int UnescapeCEscapeString(const string& src, string* dest,
440
+ vector<string> *errors) {
441
+ scoped_array<char> unescaped(new char[src.size() + 1]);
442
+ int len = UnescapeCEscapeSequences(src.c_str(), unescaped.get(), errors);
443
+ GOOGLE_CHECK(dest);
444
+ dest->assign(unescaped.get(), len);
445
+ return len;
446
+ }
447
+
448
+ string UnescapeCEscapeString(const string& src) {
449
+ scoped_array<char> unescaped(new char[src.size() + 1]);
450
+ int len = UnescapeCEscapeSequences(src.c_str(), unescaped.get(), NULL);
451
+ return string(unescaped.get(), len);
452
+ }
453
+
454
+ // ----------------------------------------------------------------------
455
+ // CEscapeString()
456
+ // CHexEscapeString()
457
+ // Copies 'src' to 'dest', escaping dangerous characters using
458
+ // C-style escape sequences. This is very useful for preparing query
459
+ // flags. 'src' and 'dest' should not overlap. The 'Hex' version uses
460
+ // hexadecimal rather than octal sequences.
461
+ // Returns the number of bytes written to 'dest' (not including the \0)
462
+ // or -1 if there was insufficient space.
463
+ //
464
+ // Currently only \n, \r, \t, ", ', \ and !isprint() chars are escaped.
465
+ // ----------------------------------------------------------------------
466
+ int CEscapeInternal(const char* src, int src_len, char* dest,
467
+ int dest_len, bool use_hex, bool utf8_safe) {
468
+ const char* src_end = src + src_len;
469
+ int used = 0;
470
+ bool last_hex_escape = false; // true if last output char was \xNN
471
+
472
+ for (; src < src_end; src++) {
473
+ if (dest_len - used < 2) // Need space for two letter escape
474
+ return -1;
475
+
476
+ bool is_hex_escape = false;
477
+ switch (*src) {
478
+ case '\n': dest[used++] = '\\'; dest[used++] = 'n'; break;
479
+ case '\r': dest[used++] = '\\'; dest[used++] = 'r'; break;
480
+ case '\t': dest[used++] = '\\'; dest[used++] = 't'; break;
481
+ case '\"': dest[used++] = '\\'; dest[used++] = '\"'; break;
482
+ case '\'': dest[used++] = '\\'; dest[used++] = '\''; break;
483
+ case '\\': dest[used++] = '\\'; dest[used++] = '\\'; break;
484
+ default:
485
+ // Note that if we emit \xNN and the src character after that is a hex
486
+ // digit then that digit must be escaped too to prevent it being
487
+ // interpreted as part of the character code by C.
488
+ if ((!utf8_safe || static_cast<uint8>(*src) < 0x80) &&
489
+ (!isprint(*src) ||
490
+ (last_hex_escape && isxdigit(*src)))) {
491
+ if (dest_len - used < 4) // need space for 4 letter escape
492
+ return -1;
493
+ sprintf(dest + used, (use_hex ? "\\x%02x" : "\\%03o"),
494
+ static_cast<uint8>(*src));
495
+ is_hex_escape = use_hex;
496
+ used += 4;
497
+ } else {
498
+ dest[used++] = *src; break;
499
+ }
500
+ }
501
+ last_hex_escape = is_hex_escape;
502
+ }
503
+
504
+ if (dest_len - used < 1) // make sure that there is room for \0
505
+ return -1;
506
+
507
+ dest[used] = '\0'; // doesn't count towards return value though
508
+ return used;
509
+ }
510
+
511
+ int CEscapeString(const char* src, int src_len, char* dest, int dest_len) {
512
+ return CEscapeInternal(src, src_len, dest, dest_len, false, false);
513
+ }
514
+
515
+ // ----------------------------------------------------------------------
516
+ // CEscape()
517
+ // CHexEscape()
518
+ // Copies 'src' to result, escaping dangerous characters using
519
+ // C-style escape sequences. This is very useful for preparing query
520
+ // flags. 'src' and 'dest' should not overlap. The 'Hex' version
521
+ // hexadecimal rather than octal sequences.
522
+ //
523
+ // Currently only \n, \r, \t, ", ', \ and !isprint() chars are escaped.
524
+ // ----------------------------------------------------------------------
525
+ string CEscape(const string& src) {
526
+ const int dest_length = src.size() * 4 + 1; // Maximum possible expansion
527
+ scoped_array<char> dest(new char[dest_length]);
528
+ const int len = CEscapeInternal(src.data(), src.size(),
529
+ dest.get(), dest_length, false, false);
530
+ GOOGLE_DCHECK_GE(len, 0);
531
+ return string(dest.get(), len);
532
+ }
533
+
534
+ namespace strings {
535
+
536
+ string Utf8SafeCEscape(const string& src) {
537
+ const int dest_length = src.size() * 4 + 1; // Maximum possible expansion
538
+ scoped_array<char> dest(new char[dest_length]);
539
+ const int len = CEscapeInternal(src.data(), src.size(),
540
+ dest.get(), dest_length, false, true);
541
+ GOOGLE_DCHECK_GE(len, 0);
542
+ return string(dest.get(), len);
543
+ }
544
+
545
+ string CHexEscape(const string& src) {
546
+ const int dest_length = src.size() * 4 + 1; // Maximum possible expansion
547
+ scoped_array<char> dest(new char[dest_length]);
548
+ const int len = CEscapeInternal(src.data(), src.size(),
549
+ dest.get(), dest_length, true, false);
550
+ GOOGLE_DCHECK_GE(len, 0);
551
+ return string(dest.get(), len);
552
+ }
553
+
554
+ } // namespace strings
555
+
556
+ // ----------------------------------------------------------------------
557
+ // strto32_adaptor()
558
+ // strtou32_adaptor()
559
+ // Implementation of strto[u]l replacements that have identical
560
+ // overflow and underflow characteristics for both ILP-32 and LP-64
561
+ // platforms, including errno preservation in error-free calls.
562
+ // ----------------------------------------------------------------------
563
+
564
+ int32 strto32_adaptor(const char *nptr, char **endptr, int base) {
565
+ const int saved_errno = errno;
566
+ errno = 0;
567
+ const long result = strtol(nptr, endptr, base);
568
+ if (errno == ERANGE && result == LONG_MIN) {
569
+ return kint32min;
570
+ } else if (errno == ERANGE && result == LONG_MAX) {
571
+ return kint32max;
572
+ } else if (errno == 0 && result < kint32min) {
573
+ errno = ERANGE;
574
+ return kint32min;
575
+ } else if (errno == 0 && result > kint32max) {
576
+ errno = ERANGE;
577
+ return kint32max;
578
+ }
579
+ if (errno == 0)
580
+ errno = saved_errno;
581
+ return static_cast<int32>(result);
582
+ }
583
+
584
+ uint32 strtou32_adaptor(const char *nptr, char **endptr, int base) {
585
+ const int saved_errno = errno;
586
+ errno = 0;
587
+ const unsigned long result = strtoul(nptr, endptr, base);
588
+ if (errno == ERANGE && result == ULONG_MAX) {
589
+ return kuint32max;
590
+ } else if (errno == 0 && result > kuint32max) {
591
+ errno = ERANGE;
592
+ return kuint32max;
593
+ }
594
+ if (errno == 0)
595
+ errno = saved_errno;
596
+ return static_cast<uint32>(result);
597
+ }
598
+
599
+ inline bool safe_parse_sign(string* text /*inout*/,
600
+ bool* negative_ptr /*output*/) {
601
+ const char* start = text->data();
602
+ const char* end = start + text->size();
603
+
604
+ // Consume whitespace.
605
+ while (start < end && (start[0] == ' ')) {
606
+ ++start;
607
+ }
608
+ while (start < end && (end[-1] == ' ')) {
609
+ --end;
610
+ }
611
+ if (start >= end) {
612
+ return false;
613
+ }
614
+
615
+ // Consume sign.
616
+ *negative_ptr = (start[0] == '-');
617
+ if (*negative_ptr || start[0] == '+') {
618
+ ++start;
619
+ if (start >= end) {
620
+ return false;
621
+ }
622
+ }
623
+ *text = text->substr(start - text->data(), end - start);
624
+ return true;
625
+ }
626
+
627
+ inline bool safe_parse_positive_int(
628
+ string text, int32* value_p) {
629
+ int base = 10;
630
+ int32 value = 0;
631
+ const int32 vmax = std::numeric_limits<int32>::max();
632
+ assert(vmax > 0);
633
+ assert(vmax >= base);
634
+ const int32 vmax_over_base = vmax / base;
635
+ const char* start = text.data();
636
+ const char* end = start + text.size();
637
+ // loop over digits
638
+ for (; start < end; ++start) {
639
+ unsigned char c = static_cast<unsigned char>(start[0]);
640
+ int digit = c - '0';
641
+ if (digit >= base || digit < 0) {
642
+ *value_p = value;
643
+ return false;
644
+ }
645
+ if (value > vmax_over_base) {
646
+ *value_p = vmax;
647
+ return false;
648
+ }
649
+ value *= base;
650
+ if (value > vmax - digit) {
651
+ *value_p = vmax;
652
+ return false;
653
+ }
654
+ value += digit;
655
+ }
656
+ *value_p = value;
657
+ return true;
658
+ }
659
+
660
+ inline bool safe_parse_negative_int(
661
+ string text, int32* value_p) {
662
+ int base = 10;
663
+ int32 value = 0;
664
+ const int32 vmin = std::numeric_limits<int32>::min();
665
+ assert(vmin < 0);
666
+ assert(vmin <= 0 - base);
667
+ int32 vmin_over_base = vmin / base;
668
+ // 2003 c++ standard [expr.mul]
669
+ // "... the sign of the remainder is implementation-defined."
670
+ // Although (vmin/base)*base + vmin%base is always vmin.
671
+ // 2011 c++ standard tightens the spec but we cannot rely on it.
672
+ if (vmin % base > 0) {
673
+ vmin_over_base += 1;
674
+ }
675
+ const char* start = text.data();
676
+ const char* end = start + text.size();
677
+ // loop over digits
678
+ for (; start < end; ++start) {
679
+ unsigned char c = static_cast<unsigned char>(start[0]);
680
+ int digit = c - '0';
681
+ if (digit >= base || digit < 0) {
682
+ *value_p = value;
683
+ return false;
684
+ }
685
+ if (value < vmin_over_base) {
686
+ *value_p = vmin;
687
+ return false;
688
+ }
689
+ value *= base;
690
+ if (value < vmin + digit) {
691
+ *value_p = vmin;
692
+ return false;
693
+ }
694
+ value -= digit;
695
+ }
696
+ *value_p = value;
697
+ return true;
698
+ }
699
+
700
+ bool safe_int(string text, int32* value_p) {
701
+ *value_p = 0;
702
+ bool negative;
703
+ if (!safe_parse_sign(&text, &negative)) {
704
+ return false;
705
+ }
706
+ if (!negative) {
707
+ return safe_parse_positive_int(text, value_p);
708
+ } else {
709
+ return safe_parse_negative_int(text, value_p);
710
+ }
711
+ }
712
+
713
+ // ----------------------------------------------------------------------
714
+ // FastIntToBuffer()
715
+ // FastInt64ToBuffer()
716
+ // FastHexToBuffer()
717
+ // FastHex64ToBuffer()
718
+ // FastHex32ToBuffer()
719
+ // ----------------------------------------------------------------------
720
+
721
+ // Offset into buffer where FastInt64ToBuffer places the end of string
722
+ // null character. Also used by FastInt64ToBufferLeft.
723
+ static const int kFastInt64ToBufferOffset = 21;
724
+
725
+ char *FastInt64ToBuffer(int64 i, char* buffer) {
726
+ // We could collapse the positive and negative sections, but that
727
+ // would be slightly slower for positive numbers...
728
+ // 22 bytes is enough to store -2**64, -18446744073709551616.
729
+ char* p = buffer + kFastInt64ToBufferOffset;
730
+ *p-- = '\0';
731
+ if (i >= 0) {
732
+ do {
733
+ *p-- = '0' + i % 10;
734
+ i /= 10;
735
+ } while (i > 0);
736
+ return p + 1;
737
+ } else {
738
+ // On different platforms, % and / have different behaviors for
739
+ // negative numbers, so we need to jump through hoops to make sure
740
+ // we don't divide negative numbers.
741
+ if (i > -10) {
742
+ i = -i;
743
+ *p-- = '0' + i;
744
+ *p = '-';
745
+ return p;
746
+ } else {
747
+ // Make sure we aren't at MIN_INT, in which case we can't say i = -i
748
+ i = i + 10;
749
+ i = -i;
750
+ *p-- = '0' + i % 10;
751
+ // Undo what we did a moment ago
752
+ i = i / 10 + 1;
753
+ do {
754
+ *p-- = '0' + i % 10;
755
+ i /= 10;
756
+ } while (i > 0);
757
+ *p = '-';
758
+ return p;
759
+ }
760
+ }
761
+ }
762
+
763
+ // Offset into buffer where FastInt32ToBuffer places the end of string
764
+ // null character. Also used by FastInt32ToBufferLeft
765
+ static const int kFastInt32ToBufferOffset = 11;
766
+
767
+ // Yes, this is a duplicate of FastInt64ToBuffer. But, we need this for the
768
+ // compiler to generate 32 bit arithmetic instructions. It's much faster, at
769
+ // least with 32 bit binaries.
770
+ char *FastInt32ToBuffer(int32 i, char* buffer) {
771
+ // We could collapse the positive and negative sections, but that
772
+ // would be slightly slower for positive numbers...
773
+ // 12 bytes is enough to store -2**32, -4294967296.
774
+ char* p = buffer + kFastInt32ToBufferOffset;
775
+ *p-- = '\0';
776
+ if (i >= 0) {
777
+ do {
778
+ *p-- = '0' + i % 10;
779
+ i /= 10;
780
+ } while (i > 0);
781
+ return p + 1;
782
+ } else {
783
+ // On different platforms, % and / have different behaviors for
784
+ // negative numbers, so we need to jump through hoops to make sure
785
+ // we don't divide negative numbers.
786
+ if (i > -10) {
787
+ i = -i;
788
+ *p-- = '0' + i;
789
+ *p = '-';
790
+ return p;
791
+ } else {
792
+ // Make sure we aren't at MIN_INT, in which case we can't say i = -i
793
+ i = i + 10;
794
+ i = -i;
795
+ *p-- = '0' + i % 10;
796
+ // Undo what we did a moment ago
797
+ i = i / 10 + 1;
798
+ do {
799
+ *p-- = '0' + i % 10;
800
+ i /= 10;
801
+ } while (i > 0);
802
+ *p = '-';
803
+ return p;
804
+ }
805
+ }
806
+ }
807
+
808
+ char *FastHexToBuffer(int i, char* buffer) {
809
+ GOOGLE_CHECK(i >= 0) << "FastHexToBuffer() wants non-negative integers, not " << i;
810
+
811
+ static const char *hexdigits = "0123456789abcdef";
812
+ char *p = buffer + 21;
813
+ *p-- = '\0';
814
+ do {
815
+ *p-- = hexdigits[i & 15]; // mod by 16
816
+ i >>= 4; // divide by 16
817
+ } while (i > 0);
818
+ return p + 1;
819
+ }
820
+
821
+ char *InternalFastHexToBuffer(uint64 value, char* buffer, int num_byte) {
822
+ static const char *hexdigits = "0123456789abcdef";
823
+ buffer[num_byte] = '\0';
824
+ for (int i = num_byte - 1; i >= 0; i--) {
825
+ #ifdef _M_X64
826
+ // MSVC x64 platform has a bug optimizing the uint32(value) in the #else
827
+ // block. Given that the uint32 cast was to improve performance on 32-bit
828
+ // platforms, we use 64-bit '&' directly.
829
+ buffer[i] = hexdigits[value & 0xf];
830
+ #else
831
+ buffer[i] = hexdigits[uint32(value) & 0xf];
832
+ #endif
833
+ value >>= 4;
834
+ }
835
+ return buffer;
836
+ }
837
+
838
+ char *FastHex64ToBuffer(uint64 value, char* buffer) {
839
+ return InternalFastHexToBuffer(value, buffer, 16);
840
+ }
841
+
842
+ char *FastHex32ToBuffer(uint32 value, char* buffer) {
843
+ return InternalFastHexToBuffer(value, buffer, 8);
844
+ }
845
+
846
+ static inline char* PlaceNum(char* p, int num, char prev_sep) {
847
+ *p-- = '0' + num % 10;
848
+ *p-- = '0' + num / 10;
849
+ *p-- = prev_sep;
850
+ return p;
851
+ }
852
+
853
+ // ----------------------------------------------------------------------
854
+ // FastInt32ToBufferLeft()
855
+ // FastUInt32ToBufferLeft()
856
+ // FastInt64ToBufferLeft()
857
+ // FastUInt64ToBufferLeft()
858
+ //
859
+ // Like the Fast*ToBuffer() functions above, these are intended for speed.
860
+ // Unlike the Fast*ToBuffer() functions, however, these functions write
861
+ // their output to the beginning of the buffer (hence the name, as the
862
+ // output is left-aligned). The caller is responsible for ensuring that
863
+ // the buffer has enough space to hold the output.
864
+ //
865
+ // Returns a pointer to the end of the string (i.e. the null character
866
+ // terminating the string).
867
+ // ----------------------------------------------------------------------
868
+
869
+ static const char two_ASCII_digits[100][2] = {
870
+ {'0','0'}, {'0','1'}, {'0','2'}, {'0','3'}, {'0','4'},
871
+ {'0','5'}, {'0','6'}, {'0','7'}, {'0','8'}, {'0','9'},
872
+ {'1','0'}, {'1','1'}, {'1','2'}, {'1','3'}, {'1','4'},
873
+ {'1','5'}, {'1','6'}, {'1','7'}, {'1','8'}, {'1','9'},
874
+ {'2','0'}, {'2','1'}, {'2','2'}, {'2','3'}, {'2','4'},
875
+ {'2','5'}, {'2','6'}, {'2','7'}, {'2','8'}, {'2','9'},
876
+ {'3','0'}, {'3','1'}, {'3','2'}, {'3','3'}, {'3','4'},
877
+ {'3','5'}, {'3','6'}, {'3','7'}, {'3','8'}, {'3','9'},
878
+ {'4','0'}, {'4','1'}, {'4','2'}, {'4','3'}, {'4','4'},
879
+ {'4','5'}, {'4','6'}, {'4','7'}, {'4','8'}, {'4','9'},
880
+ {'5','0'}, {'5','1'}, {'5','2'}, {'5','3'}, {'5','4'},
881
+ {'5','5'}, {'5','6'}, {'5','7'}, {'5','8'}, {'5','9'},
882
+ {'6','0'}, {'6','1'}, {'6','2'}, {'6','3'}, {'6','4'},
883
+ {'6','5'}, {'6','6'}, {'6','7'}, {'6','8'}, {'6','9'},
884
+ {'7','0'}, {'7','1'}, {'7','2'}, {'7','3'}, {'7','4'},
885
+ {'7','5'}, {'7','6'}, {'7','7'}, {'7','8'}, {'7','9'},
886
+ {'8','0'}, {'8','1'}, {'8','2'}, {'8','3'}, {'8','4'},
887
+ {'8','5'}, {'8','6'}, {'8','7'}, {'8','8'}, {'8','9'},
888
+ {'9','0'}, {'9','1'}, {'9','2'}, {'9','3'}, {'9','4'},
889
+ {'9','5'}, {'9','6'}, {'9','7'}, {'9','8'}, {'9','9'}
890
+ };
891
+
892
+ char* FastUInt32ToBufferLeft(uint32 u, char* buffer) {
893
+ int digits;
894
+ const char *ASCII_digits = NULL;
895
+ // The idea of this implementation is to trim the number of divides to as few
896
+ // as possible by using multiplication and subtraction rather than mod (%),
897
+ // and by outputting two digits at a time rather than one.
898
+ // The huge-number case is first, in the hopes that the compiler will output
899
+ // that case in one branch-free block of code, and only output conditional
900
+ // branches into it from below.
901
+ if (u >= 1000000000) { // >= 1,000,000,000
902
+ digits = u / 100000000; // 100,000,000
903
+ ASCII_digits = two_ASCII_digits[digits];
904
+ buffer[0] = ASCII_digits[0];
905
+ buffer[1] = ASCII_digits[1];
906
+ buffer += 2;
907
+ sublt100_000_000:
908
+ u -= digits * 100000000; // 100,000,000
909
+ lt100_000_000:
910
+ digits = u / 1000000; // 1,000,000
911
+ ASCII_digits = two_ASCII_digits[digits];
912
+ buffer[0] = ASCII_digits[0];
913
+ buffer[1] = ASCII_digits[1];
914
+ buffer += 2;
915
+ sublt1_000_000:
916
+ u -= digits * 1000000; // 1,000,000
917
+ lt1_000_000:
918
+ digits = u / 10000; // 10,000
919
+ ASCII_digits = two_ASCII_digits[digits];
920
+ buffer[0] = ASCII_digits[0];
921
+ buffer[1] = ASCII_digits[1];
922
+ buffer += 2;
923
+ sublt10_000:
924
+ u -= digits * 10000; // 10,000
925
+ lt10_000:
926
+ digits = u / 100;
927
+ ASCII_digits = two_ASCII_digits[digits];
928
+ buffer[0] = ASCII_digits[0];
929
+ buffer[1] = ASCII_digits[1];
930
+ buffer += 2;
931
+ sublt100:
932
+ u -= digits * 100;
933
+ lt100:
934
+ digits = u;
935
+ ASCII_digits = two_ASCII_digits[digits];
936
+ buffer[0] = ASCII_digits[0];
937
+ buffer[1] = ASCII_digits[1];
938
+ buffer += 2;
939
+ done:
940
+ *buffer = 0;
941
+ return buffer;
942
+ }
943
+
944
+ if (u < 100) {
945
+ digits = u;
946
+ if (u >= 10) goto lt100;
947
+ *buffer++ = '0' + digits;
948
+ goto done;
949
+ }
950
+ if (u < 10000) { // 10,000
951
+ if (u >= 1000) goto lt10_000;
952
+ digits = u / 100;
953
+ *buffer++ = '0' + digits;
954
+ goto sublt100;
955
+ }
956
+ if (u < 1000000) { // 1,000,000
957
+ if (u >= 100000) goto lt1_000_000;
958
+ digits = u / 10000; // 10,000
959
+ *buffer++ = '0' + digits;
960
+ goto sublt10_000;
961
+ }
962
+ if (u < 100000000) { // 100,000,000
963
+ if (u >= 10000000) goto lt100_000_000;
964
+ digits = u / 1000000; // 1,000,000
965
+ *buffer++ = '0' + digits;
966
+ goto sublt1_000_000;
967
+ }
968
+ // we already know that u < 1,000,000,000
969
+ digits = u / 100000000; // 100,000,000
970
+ *buffer++ = '0' + digits;
971
+ goto sublt100_000_000;
972
+ }
973
+
974
+ char* FastInt32ToBufferLeft(int32 i, char* buffer) {
975
+ uint32 u = i;
976
+ if (i < 0) {
977
+ *buffer++ = '-';
978
+ u = -i;
979
+ }
980
+ return FastUInt32ToBufferLeft(u, buffer);
981
+ }
982
+
983
+ char* FastUInt64ToBufferLeft(uint64 u64, char* buffer) {
984
+ int digits;
985
+ const char *ASCII_digits = NULL;
986
+
987
+ uint32 u = static_cast<uint32>(u64);
988
+ if (u == u64) return FastUInt32ToBufferLeft(u, buffer);
989
+
990
+ uint64 top_11_digits = u64 / 1000000000;
991
+ buffer = FastUInt64ToBufferLeft(top_11_digits, buffer);
992
+ u = u64 - (top_11_digits * 1000000000);
993
+
994
+ digits = u / 10000000; // 10,000,000
995
+ GOOGLE_DCHECK_LT(digits, 100);
996
+ ASCII_digits = two_ASCII_digits[digits];
997
+ buffer[0] = ASCII_digits[0];
998
+ buffer[1] = ASCII_digits[1];
999
+ buffer += 2;
1000
+ u -= digits * 10000000; // 10,000,000
1001
+ digits = u / 100000; // 100,000
1002
+ ASCII_digits = two_ASCII_digits[digits];
1003
+ buffer[0] = ASCII_digits[0];
1004
+ buffer[1] = ASCII_digits[1];
1005
+ buffer += 2;
1006
+ u -= digits * 100000; // 100,000
1007
+ digits = u / 1000; // 1,000
1008
+ ASCII_digits = two_ASCII_digits[digits];
1009
+ buffer[0] = ASCII_digits[0];
1010
+ buffer[1] = ASCII_digits[1];
1011
+ buffer += 2;
1012
+ u -= digits * 1000; // 1,000
1013
+ digits = u / 10;
1014
+ ASCII_digits = two_ASCII_digits[digits];
1015
+ buffer[0] = ASCII_digits[0];
1016
+ buffer[1] = ASCII_digits[1];
1017
+ buffer += 2;
1018
+ u -= digits * 10;
1019
+ digits = u;
1020
+ *buffer++ = '0' + digits;
1021
+ *buffer = 0;
1022
+ return buffer;
1023
+ }
1024
+
1025
+ char* FastInt64ToBufferLeft(int64 i, char* buffer) {
1026
+ uint64 u = i;
1027
+ if (i < 0) {
1028
+ *buffer++ = '-';
1029
+ u = -i;
1030
+ }
1031
+ return FastUInt64ToBufferLeft(u, buffer);
1032
+ }
1033
+
1034
+ // ----------------------------------------------------------------------
1035
+ // SimpleItoa()
1036
+ // Description: converts an integer to a string.
1037
+ //
1038
+ // Return value: string
1039
+ // ----------------------------------------------------------------------
1040
+
1041
+ string SimpleItoa(int i) {
1042
+ char buffer[kFastToBufferSize];
1043
+ return (sizeof(i) == 4) ?
1044
+ FastInt32ToBuffer(i, buffer) :
1045
+ FastInt64ToBuffer(i, buffer);
1046
+ }
1047
+
1048
+ string SimpleItoa(unsigned int i) {
1049
+ char buffer[kFastToBufferSize];
1050
+ return string(buffer, (sizeof(i) == 4) ?
1051
+ FastUInt32ToBufferLeft(i, buffer) :
1052
+ FastUInt64ToBufferLeft(i, buffer));
1053
+ }
1054
+
1055
+ string SimpleItoa(long i) {
1056
+ char buffer[kFastToBufferSize];
1057
+ return (sizeof(i) == 4) ?
1058
+ FastInt32ToBuffer(i, buffer) :
1059
+ FastInt64ToBuffer(i, buffer);
1060
+ }
1061
+
1062
+ string SimpleItoa(unsigned long i) {
1063
+ char buffer[kFastToBufferSize];
1064
+ return string(buffer, (sizeof(i) == 4) ?
1065
+ FastUInt32ToBufferLeft(i, buffer) :
1066
+ FastUInt64ToBufferLeft(i, buffer));
1067
+ }
1068
+
1069
+ string SimpleItoa(long long i) {
1070
+ char buffer[kFastToBufferSize];
1071
+ return (sizeof(i) == 4) ?
1072
+ FastInt32ToBuffer(i, buffer) :
1073
+ FastInt64ToBuffer(i, buffer);
1074
+ }
1075
+
1076
+ string SimpleItoa(unsigned long long i) {
1077
+ char buffer[kFastToBufferSize];
1078
+ return string(buffer, (sizeof(i) == 4) ?
1079
+ FastUInt32ToBufferLeft(i, buffer) :
1080
+ FastUInt64ToBufferLeft(i, buffer));
1081
+ }
1082
+
1083
+ // ----------------------------------------------------------------------
1084
+ // SimpleDtoa()
1085
+ // SimpleFtoa()
1086
+ // DoubleToBuffer()
1087
+ // FloatToBuffer()
1088
+ // We want to print the value without losing precision, but we also do
1089
+ // not want to print more digits than necessary. This turns out to be
1090
+ // trickier than it sounds. Numbers like 0.2 cannot be represented
1091
+ // exactly in binary. If we print 0.2 with a very large precision,
1092
+ // e.g. "%.50g", we get "0.2000000000000000111022302462515654042363167".
1093
+ // On the other hand, if we set the precision too low, we lose
1094
+ // significant digits when printing numbers that actually need them.
1095
+ // It turns out there is no precision value that does the right thing
1096
+ // for all numbers.
1097
+ //
1098
+ // Our strategy is to first try printing with a precision that is never
1099
+ // over-precise, then parse the result with strtod() to see if it
1100
+ // matches. If not, we print again with a precision that will always
1101
+ // give a precise result, but may use more digits than necessary.
1102
+ //
1103
+ // An arguably better strategy would be to use the algorithm described
1104
+ // in "How to Print Floating-Point Numbers Accurately" by Steele &
1105
+ // White, e.g. as implemented by David M. Gay's dtoa(). It turns out,
1106
+ // however, that the following implementation is about as fast as
1107
+ // DMG's code. Furthermore, DMG's code locks mutexes, which means it
1108
+ // will not scale well on multi-core machines. DMG's code is slightly
1109
+ // more accurate (in that it will never use more digits than
1110
+ // necessary), but this is probably irrelevant for most users.
1111
+ //
1112
+ // Rob Pike and Ken Thompson also have an implementation of dtoa() in
1113
+ // third_party/fmt/fltfmt.cc. Their implementation is similar to this
1114
+ // one in that it makes guesses and then uses strtod() to check them.
1115
+ // Their implementation is faster because they use their own code to
1116
+ // generate the digits in the first place rather than use snprintf(),
1117
+ // thus avoiding format string parsing overhead. However, this makes
1118
+ // it considerably more complicated than the following implementation,
1119
+ // and it is embedded in a larger library. If speed turns out to be
1120
+ // an issue, we could re-implement this in terms of their
1121
+ // implementation.
1122
+ // ----------------------------------------------------------------------
1123
+
1124
+ string SimpleDtoa(double value) {
1125
+ char buffer[kDoubleToBufferSize];
1126
+ return DoubleToBuffer(value, buffer);
1127
+ }
1128
+
1129
+ string SimpleFtoa(float value) {
1130
+ char buffer[kFloatToBufferSize];
1131
+ return FloatToBuffer(value, buffer);
1132
+ }
1133
+
1134
+ static inline bool IsValidFloatChar(char c) {
1135
+ return ('0' <= c && c <= '9') ||
1136
+ c == 'e' || c == 'E' ||
1137
+ c == '+' || c == '-';
1138
+ }
1139
+
1140
+ void DelocalizeRadix(char* buffer) {
1141
+ // Fast check: if the buffer has a normal decimal point, assume no
1142
+ // translation is needed.
1143
+ if (strchr(buffer, '.') != NULL) return;
1144
+
1145
+ // Find the first unknown character.
1146
+ while (IsValidFloatChar(*buffer)) ++buffer;
1147
+
1148
+ if (*buffer == '\0') {
1149
+ // No radix character found.
1150
+ return;
1151
+ }
1152
+
1153
+ // We are now pointing at the locale-specific radix character. Replace it
1154
+ // with '.'.
1155
+ *buffer = '.';
1156
+ ++buffer;
1157
+
1158
+ if (!IsValidFloatChar(*buffer) && *buffer != '\0') {
1159
+ // It appears the radix was a multi-byte character. We need to remove the
1160
+ // extra bytes.
1161
+ char* target = buffer;
1162
+ do { ++buffer; } while (!IsValidFloatChar(*buffer) && *buffer != '\0');
1163
+ memmove(target, buffer, strlen(buffer) + 1);
1164
+ }
1165
+ }
1166
+
1167
+ char* DoubleToBuffer(double value, char* buffer) {
1168
+ // DBL_DIG is 15 for IEEE-754 doubles, which are used on almost all
1169
+ // platforms these days. Just in case some system exists where DBL_DIG
1170
+ // is significantly larger -- and risks overflowing our buffer -- we have
1171
+ // this assert.
1172
+ GOOGLE_COMPILE_ASSERT(DBL_DIG < 20, DBL_DIG_is_too_big);
1173
+
1174
+ if (value == numeric_limits<double>::infinity()) {
1175
+ strcpy(buffer, "inf");
1176
+ return buffer;
1177
+ } else if (value == -numeric_limits<double>::infinity()) {
1178
+ strcpy(buffer, "-inf");
1179
+ return buffer;
1180
+ } else if (IsNaN(value)) {
1181
+ strcpy(buffer, "nan");
1182
+ return buffer;
1183
+ }
1184
+
1185
+ int snprintf_result =
1186
+ snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG, value);
1187
+
1188
+ // The snprintf should never overflow because the buffer is significantly
1189
+ // larger than the precision we asked for.
1190
+ GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize);
1191
+
1192
+ // We need to make parsed_value volatile in order to force the compiler to
1193
+ // write it out to the stack. Otherwise, it may keep the value in a
1194
+ // register, and if it does that, it may keep it as a long double instead
1195
+ // of a double. This long double may have extra bits that make it compare
1196
+ // unequal to "value" even though it would be exactly equal if it were
1197
+ // truncated to a double.
1198
+ volatile double parsed_value = strtod(buffer, NULL);
1199
+ if (parsed_value != value) {
1200
+ int snprintf_result =
1201
+ snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG+2, value);
1202
+
1203
+ // Should never overflow; see above.
1204
+ GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize);
1205
+ }
1206
+
1207
+ DelocalizeRadix(buffer);
1208
+ return buffer;
1209
+ }
1210
+
1211
+ bool safe_strtof(const char* str, float* value) {
1212
+ char* endptr;
1213
+ errno = 0; // errno only gets set on errors
1214
+ #if defined(_WIN32) || defined (__hpux) // has no strtof()
1215
+ *value = strtod(str, &endptr);
1216
+ #else
1217
+ *value = strtof(str, &endptr);
1218
+ #endif
1219
+ return *str != 0 && *endptr == 0 && errno == 0;
1220
+ }
1221
+
1222
+ char* FloatToBuffer(float value, char* buffer) {
1223
+ // FLT_DIG is 6 for IEEE-754 floats, which are used on almost all
1224
+ // platforms these days. Just in case some system exists where FLT_DIG
1225
+ // is significantly larger -- and risks overflowing our buffer -- we have
1226
+ // this assert.
1227
+ GOOGLE_COMPILE_ASSERT(FLT_DIG < 10, FLT_DIG_is_too_big);
1228
+
1229
+ if (value == numeric_limits<double>::infinity()) {
1230
+ strcpy(buffer, "inf");
1231
+ return buffer;
1232
+ } else if (value == -numeric_limits<double>::infinity()) {
1233
+ strcpy(buffer, "-inf");
1234
+ return buffer;
1235
+ } else if (IsNaN(value)) {
1236
+ strcpy(buffer, "nan");
1237
+ return buffer;
1238
+ }
1239
+
1240
+ int snprintf_result =
1241
+ snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG, value);
1242
+
1243
+ // The snprintf should never overflow because the buffer is significantly
1244
+ // larger than the precision we asked for.
1245
+ GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize);
1246
+
1247
+ float parsed_value;
1248
+ if (!safe_strtof(buffer, &parsed_value) || parsed_value != value) {
1249
+ int snprintf_result =
1250
+ snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG+2, value);
1251
+
1252
+ // Should never overflow; see above.
1253
+ GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize);
1254
+ }
1255
+
1256
+ DelocalizeRadix(buffer);
1257
+ return buffer;
1258
+ }
1259
+
1260
+ string ToHex(uint64 num) {
1261
+ if (num == 0) {
1262
+ return string("0");
1263
+ }
1264
+
1265
+ // Compute hex bytes in reverse order, writing to the back of the
1266
+ // buffer.
1267
+ char buf[16]; // No more than 16 hex digits needed.
1268
+ char* bufptr = buf + 16;
1269
+ static const char kHexChars[] = "0123456789abcdef";
1270
+ while (num != 0) {
1271
+ *--bufptr = kHexChars[num & 0xf];
1272
+ num >>= 4;
1273
+ }
1274
+
1275
+ return string(bufptr, buf + 16 - bufptr);
1276
+ }
1277
+
1278
+ } // namespace protobuf
1279
+ } // namespace google