Skip to content

Commit

Permalink
Fix up StringPiece in non-ICU case.
Browse files Browse the repository at this point in the history
git-svn-id: file:///dev/shm/somefilter.svn@339 e102df66-1e2e-11dd-9b44-c24451a4db5e
  • Loading branch information
kpu committed Sep 13, 2010
1 parent 96c4909 commit 2416f06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions util/string_piece.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
#include <algorithm>
#include <iostream>

#ifdef USE_ICU
U_NAMESPACE_BEGIN
#endif

std::ostream& operator<<(std::ostream& o, const StringPiece& piece) {
o.write(piece.data(), static_cast<std::streamsize>(piece.size()));
Expand All @@ -46,4 +48,6 @@ size_t hash_value(const StringPiece &str) {
return boost::hash_range(str.data(), str.data() + str.length());
}

#ifdef USE_ICU
U_NAMESPACE_END
#endif
11 changes: 8 additions & 3 deletions util/string_piece.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
#ifndef BASE_STRING_PIECE_H__
#define BASE_STRING_PIECE_H__

#define USE_ICU

#include <cstring>
#include <iosfwd>

#define USE_ICU

#ifdef USE_ICU
#include <unicode/stringpiece.h>
U_NAMESPACE_BEGIN
Expand Down Expand Up @@ -193,7 +193,12 @@ class StringPiece {
}
};

bool operator==(const StringPiece& x, const StringPiece& y);
inline bool operator==(const StringPiece& x, const StringPiece& y) {
if (x.size() != y.size())
return false;

return std::memcmp(x.data(), y.data(), x.size()) == 0;
}

inline bool operator!=(const StringPiece& x, const StringPiece& y) {
return !(x == y);
Expand Down

0 comments on commit 2416f06

Please sign in to comment.