~ubuntu-branches/debian/stretch/protobuf/stretch

« back to all changes in this revision

Viewing changes to src/google/protobuf/stubs/strutil.h

  • Committer: Package Import Robot
  • Author(s): Robert S. Edmonds
  • Date: 2014-09-11 22:50:10 UTC
  • mfrom: (10.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20140911225010-wt4yo9dpc1fzuq5g
Tags: 2.6.0-3
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
// ----------------------------------------------------------------------
127
127
// LowerString()
128
128
// UpperString()
 
129
// ToUpper()
129
130
//    Convert the characters in "s" to lowercase or uppercase.  ASCII-only:
130
131
//    these functions intentionally ignore locale because they are applied to
131
132
//    identifiers used in the Protocol Buffer language, not to natural-language
148
149
  }
149
150
}
150
151
 
 
152
inline string ToUpper(const string& s) {
 
153
  string out = s;
 
154
  UpperString(&out);
 
155
  return out;
 
156
}
 
157
 
151
158
// ----------------------------------------------------------------------
152
159
// StringReplace()
153
160
//    Give me a string and two patterns "old" and "new", and I replace
181
188
                                              vector<string>* result);
182
189
 
183
190
// ----------------------------------------------------------------------
 
191
// Split()
 
192
//    Split a string using a character delimiter.
 
193
// ----------------------------------------------------------------------
 
194
inline vector<string> Split(
 
195
    const string& full, const char* delim, bool skip_empty = true) {
 
196
  vector<string> result;
 
197
  if (skip_empty) {
 
198
    SplitStringUsing(full, delim, &result);
 
199
  } else {
 
200
    SplitStringAllowEmpty(full, delim, &result);
 
201
  }
 
202
  return result;
 
203
}
 
204
 
 
205
// ----------------------------------------------------------------------
184
206
// JoinStrings()
185
207
//    These methods concatenate a vector of strings into a C++ string, using
186
208
//    the C-string "delim" as a separator between components. There are two
327
349
}
328
350
 
329
351
// ----------------------------------------------------------------------
 
352
// safe_strto32()
 
353
// ----------------------------------------------------------------------
 
354
LIBPROTOBUF_EXPORT bool safe_int(string text, int32* value_p);
 
355
 
 
356
inline bool safe_strto32(string text, int32* value) {
 
357
  return safe_int(text, value);
 
358
}
 
359
 
 
360
// ----------------------------------------------------------------------
330
361
// FastIntToBuffer()
331
362
// FastHexToBuffer()
332
363
// FastHex64ToBuffer()
454
485
static const int kFloatToBufferSize = 24;
455
486
 
456
487
// ----------------------------------------------------------------------
457
 
// NoLocaleStrtod()
458
 
//   Exactly like strtod(), except it always behaves as if in the "C"
459
 
//   locale (i.e. decimal points must be '.'s).
460
 
// ----------------------------------------------------------------------
461
 
 
462
 
LIBPROTOBUF_EXPORT double NoLocaleStrtod(const char* text, char** endptr);
 
488
// ToString() are internal help methods used in StrCat() and Join()
 
489
// ----------------------------------------------------------------------
 
490
namespace internal {
 
491
inline string ToString(int i) {
 
492
  return SimpleItoa(i);
 
493
}
 
494
 
 
495
inline string ToString(string a) {
 
496
  return a;
 
497
}
 
498
}  // namespace internal
 
499
 
 
500
// ----------------------------------------------------------------------
 
501
// StrCat()
 
502
//    These methods join some strings together.
 
503
// ----------------------------------------------------------------------
 
504
template <typename T1, typename T2, typename T3, typename T4, typename T5>
 
505
string StrCat(
 
506
    const T1& a, const T2& b, const T3& c, const T4& d, const T5& e) {
 
507
  return internal::ToString(a) + internal::ToString(b) +
 
508
      internal::ToString(c) + internal::ToString(d) + internal::ToString(e);
 
509
}
 
510
 
 
511
template <typename T1, typename T2, typename T3, typename T4>
 
512
string StrCat(
 
513
    const T1& a, const T2& b, const T3& c, const T4& d) {
 
514
  return internal::ToString(a) + internal::ToString(b) +
 
515
      internal::ToString(c) + internal::ToString(d);
 
516
}
 
517
 
 
518
template <typename T1, typename T2, typename T3>
 
519
string StrCat(const T1& a, const T2& b, const T3& c) {
 
520
  return internal::ToString(a) + internal::ToString(b) +
 
521
      internal::ToString(c);
 
522
}
 
523
 
 
524
template <typename T1, typename T2>
 
525
string StrCat(const T1& a, const T2& b) {
 
526
  return internal::ToString(a) + internal::ToString(b);
 
527
}
 
528
 
 
529
// ----------------------------------------------------------------------
 
530
// Join()
 
531
//    These methods concatenate a range of components into a C++ string, using
 
532
//    the C-string "delim" as a separator between components.
 
533
// ----------------------------------------------------------------------
 
534
template <typename Iterator>
 
535
void Join(Iterator start, Iterator end,
 
536
          const char* delim, string* result) {
 
537
  for (Iterator it = start; it != end; ++it) {
 
538
    if (it != start) {
 
539
      result->append(delim);
 
540
    }
 
541
    result->append(internal::ToString(*it));
 
542
  }
 
543
}
 
544
 
 
545
template <typename Range>
 
546
string Join(const Range& components,
 
547
            const char* delim) {
 
548
  string result;
 
549
  Join(components.begin(), components.end(), delim, &result);
 
550
  return result;
 
551
}
 
552
 
 
553
// ----------------------------------------------------------------------
 
554
// ToHex()
 
555
//    Return a lower-case hex string representation of the given integer.
 
556
// ----------------------------------------------------------------------
 
557
LIBPROTOBUF_EXPORT string ToHex(uint64 num);
463
558
 
464
559
}  // namespace protobuf
465
560
}  // namespace google