language_detection 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. data/.gitignore +19 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +85 -0
  5. data/Rakefile +11 -0
  6. data/ext/cld/Makefile +34 -0
  7. data/ext/cld/base/basictypes.h +348 -0
  8. data/ext/cld/base/build_config.h +124 -0
  9. data/ext/cld/base/casts.h +156 -0
  10. data/ext/cld/base/commandlineflags.h +443 -0
  11. data/ext/cld/base/crash.h +41 -0
  12. data/ext/cld/base/dynamic_annotations.h +358 -0
  13. data/ext/cld/base/global_strip_options.h +59 -0
  14. data/ext/cld/base/log_severity.h +46 -0
  15. data/ext/cld/base/logging.h +1403 -0
  16. data/ext/cld/base/macros.h +243 -0
  17. data/ext/cld/base/port.h +54 -0
  18. data/ext/cld/base/scoped_ptr.h +428 -0
  19. data/ext/cld/base/stl_decl.h +0 -0
  20. data/ext/cld/base/stl_decl_msvc.h +107 -0
  21. data/ext/cld/base/string_util.h +29 -0
  22. data/ext/cld/base/strtoint.h +93 -0
  23. data/ext/cld/base/template_util.h +96 -0
  24. data/ext/cld/base/type_traits.h +198 -0
  25. data/ext/cld/base/vlog_is_on.h +143 -0
  26. data/ext/cld/cld.so +0 -0
  27. data/ext/cld/encodings/compact_lang_det/cldutil.cc +905 -0
  28. data/ext/cld/encodings/compact_lang_det/cldutil.h +1205 -0
  29. data/ext/cld/encodings/compact_lang_det/cldutil_dbg.h +76 -0
  30. data/ext/cld/encodings/compact_lang_det/cldutil_dbg_empty.cc +76 -0
  31. data/ext/cld/encodings/compact_lang_det/compact_lang_det.cc +62 -0
  32. data/ext/cld/encodings/compact_lang_det/compact_lang_det.h +145 -0
  33. data/ext/cld/encodings/compact_lang_det/compact_lang_det_impl.cc +2574 -0
  34. data/ext/cld/encodings/compact_lang_det/compact_lang_det_impl.h +173 -0
  35. data/ext/cld/encodings/compact_lang_det/compact_lang_det_unittest_small.cc +406 -0
  36. data/ext/cld/encodings/compact_lang_det/compile.cmd +1 -0
  37. data/ext/cld/encodings/compact_lang_det/ext_lang_enc.cc +545 -0
  38. data/ext/cld/encodings/compact_lang_det/ext_lang_enc.h +119 -0
  39. data/ext/cld/encodings/compact_lang_det/generated/cld_generated_score_deltaoctachrome_0406.cc +380 -0
  40. data/ext/cld/encodings/compact_lang_det/generated/cld_generated_score_quadchrome_0406.cc +382 -0
  41. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_cjkbis_0.cc +49 -0
  42. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_ctjkvz.cc +7119 -0
  43. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_ctjkvz_0.cc +61 -0
  44. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_deltaoctachrome.cc +1263 -0
  45. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_longwords8_0.cc +53 -0
  46. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_meanscore.h +10 -0
  47. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_quads_0.cc +50 -0
  48. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_quadschrome.cc +70935 -0
  49. data/ext/cld/encodings/compact_lang_det/getonescriptspan.cc +570 -0
  50. data/ext/cld/encodings/compact_lang_det/getonescriptspan.h +131 -0
  51. data/ext/cld/encodings/compact_lang_det/letterscript_enum.cc +117 -0
  52. data/ext/cld/encodings/compact_lang_det/letterscript_enum.h +99 -0
  53. data/ext/cld/encodings/compact_lang_det/subsetsequence.cc +259 -0
  54. data/ext/cld/encodings/compact_lang_det/subsetsequence.h +44 -0
  55. data/ext/cld/encodings/compact_lang_det/subsetsequence_unittest.cc +99 -0
  56. data/ext/cld/encodings/compact_lang_det/tote.cc +299 -0
  57. data/ext/cld/encodings/compact_lang_det/tote.h +89 -0
  58. data/ext/cld/encodings/compact_lang_det/unittest_data.h +193 -0
  59. data/ext/cld/encodings/compact_lang_det/utf8propjustletter.h +1162 -0
  60. data/ext/cld/encodings/compact_lang_det/utf8propletterscriptnum.h +1222 -0
  61. data/ext/cld/encodings/compact_lang_det/utf8scannotjustletterspecial.h +1185 -0
  62. data/ext/cld/encodings/compact_lang_det/win/cld_basictypes.h +10 -0
  63. data/ext/cld/encodings/compact_lang_det/win/cld_commandlineflags.h +28 -0
  64. data/ext/cld/encodings/compact_lang_det/win/cld_google.h +18 -0
  65. data/ext/cld/encodings/compact_lang_det/win/cld_htmlutils.h +13 -0
  66. data/ext/cld/encodings/compact_lang_det/win/cld_htmlutils_google3.cc +32 -0
  67. data/ext/cld/encodings/compact_lang_det/win/cld_htmlutils_windows.cc +29 -0
  68. data/ext/cld/encodings/compact_lang_det/win/cld_logging.h +21 -0
  69. data/ext/cld/encodings/compact_lang_det/win/cld_macros.h +19 -0
  70. data/ext/cld/encodings/compact_lang_det/win/cld_strtoint.h +26 -0
  71. data/ext/cld/encodings/compact_lang_det/win/cld_unicodetext.cc +84 -0
  72. data/ext/cld/encodings/compact_lang_det/win/cld_unicodetext.h +40 -0
  73. data/ext/cld/encodings/compact_lang_det/win/cld_unilib.h +15 -0
  74. data/ext/cld/encodings/compact_lang_det/win/cld_unilib_google3.cc +18 -0
  75. data/ext/cld/encodings/compact_lang_det/win/cld_unilib_windows.cc +29 -0
  76. data/ext/cld/encodings/compact_lang_det/win/cld_utf.h +24 -0
  77. data/ext/cld/encodings/compact_lang_det/win/cld_utf8statetable.cc +224 -0
  78. data/ext/cld/encodings/compact_lang_det/win/cld_utf8statetable.h +141 -0
  79. data/ext/cld/encodings/compact_lang_det/win/cld_utf8utils.h +22 -0
  80. data/ext/cld/encodings/compact_lang_det/win/cld_utf8utils_google3.cc +18 -0
  81. data/ext/cld/encodings/compact_lang_det/win/cld_utf8utils_windows.cc +17 -0
  82. data/ext/cld/encodings/compact_lang_det/win/normalizedunicodetext.cc +172 -0
  83. data/ext/cld/encodings/compact_lang_det/win/normalizedunicodetext.h +67 -0
  84. data/ext/cld/encodings/internal/encodings.cc +12 -0
  85. data/ext/cld/encodings/lang_enc.h +254 -0
  86. data/ext/cld/encodings/proto/encodings.pb.h +169 -0
  87. data/ext/cld/encodings/public/encodings.h +301 -0
  88. data/ext/cld/extconf.rb +1 -0
  89. data/ext/cld/language_detection.cc +88 -0
  90. data/ext/cld/languages/internal/languages.cc +337 -0
  91. data/ext/cld/languages/proto/languages.pb.h +179 -0
  92. data/ext/cld/languages/public/languages.h +379 -0
  93. data/language_detection.gemspec +28 -0
  94. data/lib/language_detection/string.rb +1 -0
  95. data/lib/language_detection/version.rb +3 -0
  96. data/lib/language_detection.rb +54 -0
  97. data/test/_helper.rb +15 -0
  98. data/test/fixtures/languages.csv +80 -0
  99. data/test/language_detection_test.rb +88 -0
  100. metadata +250 -0
@@ -0,0 +1,428 @@
1
+ // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ #ifndef BASE_SCOPED_PTR_H__
6
+ #define BASE_SCOPED_PTR_H__
7
+
8
+ // This is an implementation designed to match the anticipated future TR2
9
+ // implementation of the scoped_ptr class, and its closely-related brethren,
10
+ // scoped_array, scoped_ptr_malloc, and make_scoped_ptr.
11
+ //
12
+ // See http://wiki/Main/ScopedPointerInterface for the spec that drove this
13
+ // file.
14
+
15
+ #include <assert.h>
16
+ #include <stdlib.h>
17
+ #include <cstddef>
18
+
19
+ #ifdef OS_EMBEDDED_QNX
20
+ // NOTE(akirmse):
21
+ // The C++ standard says that <stdlib.h> declares both ::foo and std::foo
22
+ // But this isn't done in QNX version 6.3.2 200709062316.
23
+ using std::free;
24
+ using std::malloc;
25
+ using std::realloc;
26
+ #endif
27
+
28
+ template <class C> class scoped_ptr;
29
+ template <class C, class Free> class scoped_ptr_malloc;
30
+ template <class C> class scoped_array;
31
+
32
+ template <class C>
33
+ scoped_ptr<C> make_scoped_ptr(C *);
34
+
35
+ // A scoped_ptr<T> is like a T*, except that the destructor of scoped_ptr<T>
36
+ // automatically deletes the pointer it holds (if any).
37
+ // That is, scoped_ptr<T> owns the T object that it points to.
38
+ // Like a T*, a scoped_ptr<T> may hold either NULL or a pointer to a T object.
39
+ // Also like T*, scoped_ptr<T> is thread-compatible, and once you
40
+ // dereference it, you get the threadsafety guarantees of T.
41
+ //
42
+ // The size of a scoped_ptr is small:
43
+ // sizeof(scoped_ptr<C>) == sizeof(C*)
44
+ template <class C>
45
+ class scoped_ptr {
46
+ public:
47
+
48
+ // The element type
49
+ typedef C element_type;
50
+
51
+ // Constructor. Defaults to intializing with NULL.
52
+ // There is no way to create an uninitialized scoped_ptr.
53
+ // The input parameter must be allocated with new.
54
+ explicit scoped_ptr(C* p = NULL) : ptr_(p) { }
55
+
56
+ // Destructor. If there is a C object, delete it.
57
+ // We don't need to test ptr_ == NULL because C++ does that for us.
58
+ ~scoped_ptr() {
59
+ enum { type_must_be_complete = sizeof(C) };
60
+ delete ptr_;
61
+ }
62
+
63
+ // Reset. Deletes the current owned object, if any.
64
+ // Then takes ownership of a new object, if given.
65
+ // this->reset(this->get()) works.
66
+ void reset(C* p = NULL) {
67
+ if (p != ptr_) {
68
+ enum { type_must_be_complete = sizeof(C) };
69
+ delete ptr_;
70
+ ptr_ = p;
71
+ }
72
+ }
73
+
74
+ // Accessors to get the owned object.
75
+ // operator* and operator-> will assert() if there is no current object.
76
+ C& operator*() const {
77
+ assert(ptr_ != NULL);
78
+ return *ptr_;
79
+ }
80
+ C* operator->() const {
81
+ assert(ptr_ != NULL);
82
+ return ptr_;
83
+ }
84
+ C* get() const { return ptr_; }
85
+
86
+ // Comparison operators.
87
+ // These return whether a scoped_ptr and a raw pointer refer to
88
+ // the same object, not just to two different but equal objects.
89
+ bool operator==(const C* p) const { return ptr_ == p; }
90
+ bool operator!=(const C* p) const { return ptr_ != p; }
91
+
92
+ // Swap two scoped pointers.
93
+ void swap(scoped_ptr& p2) {
94
+ C* tmp = ptr_;
95
+ ptr_ = p2.ptr_;
96
+ p2.ptr_ = tmp;
97
+ }
98
+
99
+ // Release a pointer.
100
+ // The return value is the current pointer held by this object.
101
+ // If this object holds a NULL pointer, the return value is NULL.
102
+ // After this operation, this object will hold a NULL pointer,
103
+ // and will not own the object any more.
104
+ C* release() {
105
+ C* retVal = ptr_;
106
+ ptr_ = NULL;
107
+ return retVal;
108
+ }
109
+
110
+ private:
111
+ C* ptr_;
112
+
113
+ // google3 friend class that can access copy ctor (although if it actually
114
+ // calls a copy ctor, there will be a problem) see below
115
+ friend scoped_ptr<C> make_scoped_ptr<C>(C *p);
116
+
117
+ // Forbid comparison of scoped_ptr types. If C2 != C, it totally doesn't
118
+ // make sense, and if C2 == C, it still doesn't make sense because you should
119
+ // never have the same object owned by two different scoped_ptrs.
120
+ template <class C2> bool operator==(scoped_ptr<C2> const& p2) const;
121
+ template <class C2> bool operator!=(scoped_ptr<C2> const& p2) const;
122
+
123
+ // Disallow evil constructors
124
+ scoped_ptr(const scoped_ptr&);
125
+ void operator=(const scoped_ptr&);
126
+ };
127
+
128
+ // Free functions
129
+ template <class C>
130
+ inline void swap(scoped_ptr<C>& p1, scoped_ptr<C>& p2) {
131
+ p1.swap(p2);
132
+ }
133
+
134
+ template <class C>
135
+ inline bool operator==(const C* p1, const scoped_ptr<C>& p2) {
136
+ return p1 == p2.get();
137
+ }
138
+
139
+ template <class C>
140
+ inline bool operator==(const C* p1, const scoped_ptr<const C>& p2) {
141
+ return p1 == p2.get();
142
+ }
143
+
144
+ template <class C>
145
+ inline bool operator!=(const C* p1, const scoped_ptr<C>& p2) {
146
+ return p1 != p2.get();
147
+ }
148
+
149
+ template <class C>
150
+ inline bool operator!=(const C* p1, const scoped_ptr<const C>& p2) {
151
+ return p1 != p2.get();
152
+ }
153
+
154
+ template <class C>
155
+ scoped_ptr<C> make_scoped_ptr(C *p) {
156
+ // This does nothing but to return a scoped_ptr of the type that the passed
157
+ // pointer is of. (This eliminates the need to specify the name of T when
158
+ // making a scoped_ptr that is used anonymously/temporarily.) From an
159
+ // access control point of view, we construct an unnamed scoped_ptr here
160
+ // which we return and thus copy-construct. Hence, we need to have access
161
+ // to scoped_ptr::scoped_ptr(scoped_ptr const &). However, it is guaranteed
162
+ // that we never actually call the copy constructor, which is a good thing
163
+ // as we would call the temporary's object destructor (and thus delete p)
164
+ // if we actually did copy some object, here.
165
+ return scoped_ptr<C>(p);
166
+ }
167
+
168
+ // scoped_array<C> is like scoped_ptr<C>, except that the caller must allocate
169
+ // with new [] and the destructor deletes objects with delete [].
170
+ //
171
+ // As with scoped_ptr<C>, a scoped_array<C> either points to an object
172
+ // or is NULL. A scoped_array<C> owns the object that it points to.
173
+ // scoped_array<T> is thread-compatible, and once you index into it,
174
+ // the returned objects have only the threadsafety guarantees of T.
175
+ //
176
+ // Size: sizeof(scoped_array<C>) == sizeof(C*)
177
+ template <class C>
178
+ class scoped_array {
179
+ public:
180
+
181
+ // The element type
182
+ typedef C element_type;
183
+
184
+ // Constructor. Defaults to intializing with NULL.
185
+ // There is no way to create an uninitialized scoped_array.
186
+ // The input parameter must be allocated with new [].
187
+ explicit scoped_array(C* p = NULL) : array_(p) { }
188
+
189
+ // Destructor. If there is a C object, delete it.
190
+ // We don't need to test ptr_ == NULL because C++ does that for us.
191
+ ~scoped_array() {
192
+ enum { type_must_be_complete = sizeof(C) };
193
+ delete[] array_;
194
+ }
195
+
196
+ // Reset. Deletes the current owned object, if any.
197
+ // Then takes ownership of a new object, if given.
198
+ // this->reset(this->get()) works.
199
+ void reset(C* p = NULL) {
200
+ if (p != array_) {
201
+ enum { type_must_be_complete = sizeof(C) };
202
+ delete[] array_;
203
+ array_ = p;
204
+ }
205
+ }
206
+
207
+ // Get one element of the current object.
208
+ // Will assert() if there is no current object, or index i is negative.
209
+ C& operator[](std::ptrdiff_t i) const {
210
+ assert(i >= 0);
211
+ assert(array_ != NULL);
212
+ return array_[i];
213
+ }
214
+
215
+ // Get a pointer to the zeroth element of the current object.
216
+ // If there is no current object, return NULL.
217
+ C* get() const {
218
+ return array_;
219
+ }
220
+
221
+ // Comparison operators.
222
+ // These return whether a scoped_array and a raw pointer refer to
223
+ // the same array, not just to two different but equal arrays.
224
+ bool operator==(const C* p) const { return array_ == p; }
225
+ bool operator!=(const C* p) const { return array_ != p; }
226
+
227
+ // Swap two scoped arrays.
228
+ void swap(scoped_array& p2) {
229
+ C* tmp = array_;
230
+ array_ = p2.array_;
231
+ p2.array_ = tmp;
232
+ }
233
+
234
+ // Release an array.
235
+ // The return value is the current pointer held by this object.
236
+ // If this object holds a NULL pointer, the return value is NULL.
237
+ // After this operation, this object will hold a NULL pointer,
238
+ // and will not own the object any more.
239
+ C* release() {
240
+ C* retVal = array_;
241
+ array_ = NULL;
242
+ return retVal;
243
+ }
244
+
245
+ private:
246
+ C* array_;
247
+
248
+ // Forbid comparison of different scoped_array types.
249
+ template <class C2> bool operator==(scoped_array<C2> const& p2) const;
250
+ template <class C2> bool operator!=(scoped_array<C2> const& p2) const;
251
+
252
+ // Disallow evil constructors
253
+ scoped_array(const scoped_array&);
254
+ void operator=(const scoped_array&);
255
+ };
256
+
257
+ // Free functions
258
+ template <class C>
259
+ inline void swap(scoped_array<C>& p1, scoped_array<C>& p2) {
260
+ p1.swap(p2);
261
+ }
262
+
263
+ template <class C>
264
+ inline bool operator==(const C* p1, const scoped_array<C>& p2) {
265
+ return p1 == p2.get();
266
+ }
267
+
268
+ template <class C>
269
+ inline bool operator==(const C* p1, const scoped_array<const C>& p2) {
270
+ return p1 == p2.get();
271
+ }
272
+
273
+ template <class C>
274
+ inline bool operator!=(const C* p1, const scoped_array<C>& p2) {
275
+ return p1 != p2.get();
276
+ }
277
+
278
+ template <class C>
279
+ inline bool operator!=(const C* p1, const scoped_array<const C>& p2) {
280
+ return p1 != p2.get();
281
+ }
282
+
283
+ // This class wraps the c library function free() in a class that can be
284
+ // passed as a template argument to scoped_ptr_malloc below.
285
+ class ScopedPtrMallocFree {
286
+ public:
287
+ inline void operator()(void* x) const {
288
+ free(x);
289
+ }
290
+ };
291
+
292
+ // scoped_ptr_malloc<> is similar to scoped_ptr<>, but it accepts a
293
+ // second template argument, the functor used to free the object.
294
+
295
+ template<class C, class FreeProc = ScopedPtrMallocFree>
296
+ class scoped_ptr_malloc {
297
+ public:
298
+
299
+ // The element type
300
+ typedef C element_type;
301
+
302
+ // Construction with no arguments sets ptr_ to NULL.
303
+ // There is no way to create an uninitialized scoped_ptr.
304
+ // The input parameter must be allocated with an allocator that matches the
305
+ // Free functor. For the default Free functor, this is malloc, calloc, or
306
+ // realloc.
307
+ explicit scoped_ptr_malloc(): ptr_(NULL) { }
308
+
309
+ // Construct with a C*, and provides an error with a D*.
310
+ template<class must_be_C>
311
+ explicit scoped_ptr_malloc(must_be_C* p): ptr_(p) { }
312
+
313
+ // Construct with a void*, such as you get from malloc.
314
+ explicit scoped_ptr_malloc(void *p): ptr_(static_cast<C*>(p)) { }
315
+
316
+ // Destructor. If there is a C object, call the Free functor.
317
+ ~scoped_ptr_malloc() {
318
+ free_(ptr_);
319
+ }
320
+
321
+ // Reset. Calls the Free functor on the current owned object, if any.
322
+ // Then takes ownership of a new object, if given.
323
+ // this->reset(this->get()) works.
324
+ void reset(C* p = NULL) {
325
+ if (ptr_ != p) {
326
+ free_(ptr_);
327
+ ptr_ = p;
328
+ }
329
+ }
330
+
331
+ // Reallocates the existing pointer, and returns 'true' if
332
+ // the reallcation is succesfull. If the reallocation failed, then
333
+ // the pointer remains in its previous state.
334
+ //
335
+ // Note: this calls realloc() directly, even if an alternate 'free'
336
+ // functor is provided in the template instantiation.
337
+ bool try_realloc(size_t new_size) {
338
+ C* new_ptr = static_cast<C*>(realloc(ptr_, new_size));
339
+ if (new_ptr == NULL) {
340
+ return false;
341
+ }
342
+ ptr_ = new_ptr;
343
+ return true;
344
+ }
345
+
346
+ // Get the current object.
347
+ // operator* and operator-> will cause an assert() failure if there is
348
+ // no current object.
349
+ C& operator*() const {
350
+ assert(ptr_ != NULL);
351
+ return *ptr_;
352
+ }
353
+
354
+ C* operator->() const {
355
+ assert(ptr_ != NULL);
356
+ return ptr_;
357
+ }
358
+
359
+ C* get() const {
360
+ return ptr_;
361
+ }
362
+
363
+ // Comparison operators.
364
+ // These return whether a scoped_ptr_malloc and a plain pointer refer
365
+ // to the same object, not just to two different but equal objects.
366
+ // For compatibility with the boost-derived implementation, these
367
+ // take non-const arguments.
368
+ bool operator==(C* p) const {
369
+ return ptr_ == p;
370
+ }
371
+
372
+ bool operator!=(C* p) const {
373
+ return ptr_ != p;
374
+ }
375
+
376
+ // Swap two scoped pointers.
377
+ void swap(scoped_ptr_malloc & b) {
378
+ C* tmp = b.ptr_;
379
+ b.ptr_ = ptr_;
380
+ ptr_ = tmp;
381
+ }
382
+
383
+ // Release a pointer.
384
+ // The return value is the current pointer held by this object.
385
+ // If this object holds a NULL pointer, the return value is NULL.
386
+ // After this operation, this object will hold a NULL pointer,
387
+ // and will not own the object any more.
388
+ C* release() {
389
+ C* tmp = ptr_;
390
+ ptr_ = NULL;
391
+ return tmp;
392
+ }
393
+
394
+ private:
395
+ C* ptr_;
396
+
397
+ // no reason to use these: each scoped_ptr_malloc should have its own object
398
+ template <class C2, class GP>
399
+ bool operator==(scoped_ptr_malloc<C2, GP> const& p) const;
400
+ template <class C2, class GP>
401
+ bool operator!=(scoped_ptr_malloc<C2, GP> const& p) const;
402
+
403
+ static FreeProc const free_;
404
+
405
+ // Disallow evil constructors
406
+ scoped_ptr_malloc(const scoped_ptr_malloc&);
407
+ void operator=(const scoped_ptr_malloc&);
408
+ };
409
+
410
+ template<class C, class FP>
411
+ FP const scoped_ptr_malloc<C, FP>::free_ = FP();
412
+
413
+ template<class C, class FP> inline
414
+ void swap(scoped_ptr_malloc<C, FP>& a, scoped_ptr_malloc<C, FP>& b) {
415
+ a.swap(b);
416
+ }
417
+
418
+ template<class C, class FP> inline
419
+ bool operator==(C* p, const scoped_ptr_malloc<C, FP>& b) {
420
+ return p == b.get();
421
+ }
422
+
423
+ template<class C, class FP> inline
424
+ bool operator!=(C* p, const scoped_ptr_malloc<C, FP>& b) {
425
+ return p != b.get();
426
+ }
427
+
428
+ #endif // BASE_SCOPED_PTR_H__
File without changes
@@ -0,0 +1,107 @@
1
+ // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // In most .h files, we would rather include a declaration of an stl
6
+ // rather than including the appropriate stl h file (which brings in
7
+ // lots of noise). For many STL classes this is ok (eg pair), but for
8
+ // some it's really annoying. We define those here, so you can
9
+ // just include this file instead of having to deal with the annoyance.
10
+ //
11
+ // Most of the annoyance, btw, has to do with the default allocator.
12
+
13
+ #ifndef _STL_DECL_MSVC_H
14
+ #define _STL_DECL_MSVC_H
15
+
16
+ // VC++ namespace / STL issues; make them explicit
17
+ #include <wchar.h>
18
+ #include <string>
19
+ #include <vector>
20
+ #include <functional>
21
+ #include <utility>
22
+ #include <set>
23
+ #include <list>
24
+ #define slist list
25
+ #include <algorithm>
26
+ #include <deque>
27
+ #include <iostream>
28
+ #include <map>
29
+ #include <queue>
30
+ #include <stack>
31
+
32
+ // copy_n isn't to be found anywhere in MSVC's STL
33
+ template <typename InputIterator, typename Size, typename OutputIterator>
34
+ std::pair<InputIterator, OutputIterator>
35
+ copy_n(InputIterator in, Size count, OutputIterator out) {
36
+ for ( ; count > 0; --count) {
37
+ *out = *in;
38
+ ++out;
39
+ ++in;
40
+ }
41
+ return std::make_pair(in, out);
42
+ }
43
+
44
+ // Nor are the following selectors
45
+ template <typename T>
46
+ struct identity {
47
+ inline const T& operator()(const T& t) const { return t; }
48
+ };
49
+
50
+ // Copied from STLport
51
+ template <class _Pair>
52
+ struct select1st : public std::unary_function<_Pair, typename _Pair::first_type> {
53
+ const typename _Pair::first_type& operator()(const _Pair& __x) const {
54
+ return __x.first;
55
+ }
56
+ };
57
+
58
+ template <class _Pair>
59
+ struct select2nd : public std::unary_function<_Pair, typename _Pair::second_type>
60
+ {
61
+ const typename _Pair::second_type& operator()(const _Pair& __x) const {
62
+ return __x.second;
63
+ }
64
+ };
65
+
66
+
67
+ #if _MSC_VER >= 1300
68
+
69
+ // If you compile on Windows and get a compile-time error because
70
+ // some google3 code specifies a 3rd or 4th parameter to one of
71
+ // these template classes, then you have to put in some #ifdefs
72
+ // and use the NATIVE_HASH_NAMESPACE::hash_(set|map) implementation.
73
+ namespace msvchash {
74
+ template <typename Key>
75
+ struct hash;
76
+
77
+ template <class Key,
78
+ class HashFcn = hash<Key> >
79
+ class hash_set;
80
+
81
+ template <class Key, class Val,
82
+ class HashFcn = hash<Key> >
83
+ class hash_map;
84
+
85
+ template <class Key,
86
+ class HashFcn = hash<Key> >
87
+ class hash_multiset;
88
+
89
+ template <class Key, class Val,
90
+ class HashFcn = hash<Key> >
91
+ class hash_multimap;
92
+ } // end namespace msvchash
93
+
94
+ using msvchash::hash_set;
95
+ using msvchash::hash_map;
96
+ using msvchash::hash;
97
+ using msvchash::hash_multimap;
98
+ using msvchash::hash_multiset;
99
+
100
+ #else
101
+ #define hash_map map
102
+ #define hash_set set
103
+ #endif
104
+
105
+ using namespace std;
106
+
107
+ #endif /* #ifdef _STL_DECL_MSVC_H */
@@ -0,0 +1,29 @@
1
+ // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ //
5
+ // This file defines utility functions for working with strings.
6
+
7
+ #ifndef BASE_STRING_UTIL_H_
8
+ #define BASE_STRING_UTIL_H_
9
+
10
+ #include <string.h>
11
+
12
+ namespace base {
13
+
14
+ #ifdef WIN32
15
+ // Compare the two strings s1 and s2 without regard to case using
16
+ // the current locale; returns 0 if they are equal, 1 if s1 > s2, and -1 if
17
+ // s2 > s1 according to a lexicographic comparison.
18
+ inline int strcasecmp(const char* s1, const char* s2) {
19
+ return _stricmp(s1, s2);
20
+ }
21
+ #else
22
+ inline int strcasecmp(const char* s1, const char* s2) {
23
+ return ::strcasecmp(s1, s2);
24
+ }
25
+ #endif
26
+
27
+ }
28
+
29
+ #endif // BASE_STRING_UTIL_H_
@@ -0,0 +1,93 @@
1
+ // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // Architecture-neutral plug compatible replacements for strtol() friends.
6
+ //
7
+ // Long's have different lengths on ILP-32 and LP-64 platforms, and so overflow
8
+ // behavior across the two varies when strtol() and similar are used to parse
9
+ // 32-bit integers. Similar problems exist with atoi(), because although it
10
+ // has an all-integer interface, it uses strtol() internally, and so suffers
11
+ // from the same narrowing problems on assignments to int.
12
+ //
13
+ // Examples:
14
+ // errno = 0;
15
+ // i = strtol("3147483647", NULL, 10);
16
+ // printf("%d, errno %d\n", i, errno);
17
+ // // 32-bit platform: 2147483647, errno 34
18
+ // // 64-bit platform: -1147483649, errno 0
19
+ //
20
+ // printf("%d\n", atoi("3147483647"));
21
+ // // 32-bit platform: 2147483647
22
+ // // 64-bit platform: -1147483649
23
+ //
24
+ // A way round this is to define local replacements for these, and use them
25
+ // instead of the standard libc functions.
26
+ //
27
+ // In most 32-bit cases the replacements can be inlined away to a call to the
28
+ // libc function. In a couple of 64-bit cases, however, adapters are required,
29
+ // to provide the right overflow and errno behavior.
30
+ //
31
+
32
+ #ifndef BASE_STRTOINT_H_
33
+ #define BASE_STRTOINT_H_
34
+
35
+ #include <stdlib.h> // For strtol* functions.
36
+ #include <string>
37
+ #include "base/port.h"
38
+ #include "base/basictypes.h"
39
+
40
+ // Adapter functions for handling overflow and errno.
41
+ int32 strto32_adapter(const char *nptr, char **endptr, int base);
42
+ uint32 strtou32_adapter(const char *nptr, char **endptr, int base);
43
+
44
+ // Conversions to a 32-bit integer can pass the call to strto[u]l on 32-bit
45
+ // platforms, but need a little extra work on 64-bit platforms.
46
+ inline int32 strto32(const char *nptr, char **endptr, int base) {
47
+ if (sizeof(int32) == sizeof(long))
48
+ return strtol(nptr, endptr, base);
49
+ else
50
+ return strto32_adapter(nptr, endptr, base);
51
+ }
52
+
53
+ inline uint32 strtou32(const char *nptr, char **endptr, int base) {
54
+ if (sizeof(uint32) == sizeof(unsigned long))
55
+ return strtoul(nptr, endptr, base);
56
+ else
57
+ return strtou32_adapter(nptr, endptr, base);
58
+ }
59
+
60
+ // For now, long long is 64-bit on all the platforms we care about, so these
61
+ // functions can simply pass the call to strto[u]ll.
62
+ inline int64 strto64(const char *nptr, char **endptr, int base) {
63
+ COMPILE_ASSERT(sizeof(int64) == sizeof(long long),
64
+ sizeof_int64_is_not_sizeof_long_long);
65
+ return strtoll(nptr, endptr, base);
66
+ }
67
+
68
+ inline uint64 strtou64(const char *nptr, char **endptr, int base) {
69
+ COMPILE_ASSERT(sizeof(uint64) == sizeof(unsigned long long),
70
+ sizeof_uint64_is_not_sizeof_long_long);
71
+ return strtoull(nptr, endptr, base);
72
+ }
73
+
74
+ // Although it returns an int, atoi() is implemented in terms of strtol, and
75
+ // so has differing overflow and underflow behavior. atol is the same.
76
+ inline int32 atoi32(const char *nptr) {
77
+ return strto32(nptr, NULL, 10);
78
+ }
79
+
80
+ inline int64 atoi64(const char *nptr) {
81
+ return strto64(nptr, NULL, 10);
82
+ }
83
+
84
+ // Convenience versions of the above that take a string argument.
85
+ inline int32 atoi32(const string &s) {
86
+ return atoi32(s.c_str());
87
+ }
88
+
89
+ inline int64 atoi64(const string &s) {
90
+ return atoi64(s.c_str());
91
+ }
92
+
93
+ #endif // BASE_STRTOINT_H_