aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/cpp/util')
-rw-r--r--src/main/cpp/util/file.cc4
-rw-r--r--src/main/cpp/util/file.h8
-rw-r--r--src/main/cpp/util/file_posix.cc9
-rw-r--r--src/main/cpp/util/file_posix.h4
-rw-r--r--src/main/cpp/util/md5.cc2
-rw-r--r--src/main/cpp/util/md5.h4
-rw-r--r--src/main/cpp/util/numbers.cc2
-rw-r--r--src/main/cpp/util/numbers.h4
-rw-r--r--src/main/cpp/util/strings.cc5
-rw-r--r--src/main/cpp/util/strings.h49
10 files changed, 46 insertions, 45 deletions
diff --git a/src/main/cpp/util/file.cc b/src/main/cpp/util/file.cc
index f453176b00..0957a567e6 100644
--- a/src/main/cpp/util/file.cc
+++ b/src/main/cpp/util/file.cc
@@ -18,14 +18,16 @@
#include <cstdlib>
#include <vector>
-#include "src/main/cpp/util/exit_code.h"
#include "src/main/cpp/util/errors.h"
+#include "src/main/cpp/util/exit_code.h"
#include "src/main/cpp/util/strings.h"
using std::pair;
namespace blaze_util {
+using std::string;
+
pair<string, string> SplitPath(const string &path) {
size_t pos = path.rfind('/');
diff --git a/src/main/cpp/util/file.h b/src/main/cpp/util/file.h
index 6e7707b32b..238ccf0d9f 100644
--- a/src/main/cpp/util/file.h
+++ b/src/main/cpp/util/file.h
@@ -18,18 +18,16 @@
namespace blaze_util {
-using std::string;
-
// Returns the part of the path before the final "/". If there is a single
// leading "/" in the path, the result will be the leading "/". If there is
// no "/" in the path, the result is the empty prefix of the input (i.e., "").
-string Dirname(const string &path);
+std::string Dirname(const std::string &path);
// Returns the part of the path after the final "/". If there is no
// "/" in the path, the result is the same as the input.
-string Basename(const string &path);
+std::string Basename(const std::string &path);
-string JoinPath(const string &path1, const string &path2);
+std::string JoinPath(const std::string &path1, const std::string &path2);
} // namespace blaze_util
diff --git a/src/main/cpp/util/file_posix.cc b/src/main/cpp/util/file_posix.cc
index 51df0dcd37..ff85e21b6c 100644
--- a/src/main/cpp/util/file_posix.cc
+++ b/src/main/cpp/util/file_posix.cc
@@ -18,15 +18,16 @@
#include <unistd.h> // access
#include <vector>
-#include "src/main/cpp/util/file.h"
-#include "src/main/cpp/util/exit_code.h"
#include "src/main/cpp/util/errors.h"
+#include "src/main/cpp/util/exit_code.h"
+#include "src/main/cpp/util/file.h"
#include "src/main/cpp/util/strings.h"
-using std::pair;
-
namespace blaze_util {
+using std::pair;
+using std::string;
+
string Which(const string &executable) {
char *path_cstr = getenv("PATH");
if (path_cstr == NULL || path_cstr[0] == '\0') {
diff --git a/src/main/cpp/util/file_posix.h b/src/main/cpp/util/file_posix.h
index 42ced01b21..1d247bcdd4 100644
--- a/src/main/cpp/util/file_posix.h
+++ b/src/main/cpp/util/file_posix.h
@@ -19,12 +19,10 @@
namespace blaze_util {
-using std::string;
-
// Checks each element of the PATH variable for executable. If none is found, ""
// is returned. Otherwise, the full path to executable is returned. Can die if
// looking up PATH fails.
-string Which(const string &executable);
+std::string Which(const std::string &executable);
} // namespace blaze_util
diff --git a/src/main/cpp/util/md5.cc b/src/main/cpp/util/md5.cc
index d25c292787..770378533a 100644
--- a/src/main/cpp/util/md5.cc
+++ b/src/main/cpp/util/md5.cc
@@ -57,6 +57,8 @@
namespace blaze_util {
+using std::string;
+
static const unsigned int k8Bytes = 64;
static const unsigned int k8ByteMask = 63;
diff --git a/src/main/cpp/util/md5.h b/src/main/cpp/util/md5.h
index e4c5836229..d153a44ad4 100644
--- a/src/main/cpp/util/md5.h
+++ b/src/main/cpp/util/md5.h
@@ -26,8 +26,6 @@
namespace blaze_util {
-using std::string;
-
// The <code>Context</code> class performs the actual MD5
// computation. It works incrementally and can be fed a single byte at
// a time if desired.
@@ -55,7 +53,7 @@ class Md5Digest {
// Produces a hexadecimal string representation of this digest in the form:
// [0-9a-f]{32}
- string String() const;
+ std::string String() const;
private:
void Transform(const unsigned char* buffer, unsigned int len);
diff --git a/src/main/cpp/util/numbers.cc b/src/main/cpp/util/numbers.cc
index 46feb81eda..b0ac3980a4 100644
--- a/src/main/cpp/util/numbers.cc
+++ b/src/main/cpp/util/numbers.cc
@@ -24,6 +24,8 @@
namespace blaze_util {
+using std::string;
+
static const int32_t kint32min = static_cast<int32_t>(~0x7FFFFFFF);
static const int32_t kint32max = static_cast<int32_t>(0x7FFFFFFF);
diff --git a/src/main/cpp/util/numbers.h b/src/main/cpp/util/numbers.h
index 2dca80f991..f1ef6f7991 100644
--- a/src/main/cpp/util/numbers.h
+++ b/src/main/cpp/util/numbers.h
@@ -18,9 +18,7 @@
namespace blaze_util {
-using std::string;
-
-bool safe_strto32(const string &text, int *value);
+bool safe_strto32(const std::string &text, int *value);
int32_t strto32(const char *str, char **endptr, int base);
diff --git a/src/main/cpp/util/strings.cc b/src/main/cpp/util/strings.cc
index 3df0b9ed2b..e20bf80d8e 100644
--- a/src/main/cpp/util/strings.cc
+++ b/src/main/cpp/util/strings.cc
@@ -21,10 +21,11 @@
#include "src/main/cpp/util/exit_code.h"
-using std::vector;
-
namespace blaze_util {
+using std::string;
+using std::vector;
+
static const char kSeparator[] = " \n\t\r";
// # Table generated by this Python code (bit 0x02 is currently unused):
diff --git a/src/main/cpp/util/strings.h b/src/main/cpp/util/strings.h
index 0dca21929d..4724558baf 100644
--- a/src/main/cpp/util/strings.h
+++ b/src/main/cpp/util/strings.h
@@ -23,16 +23,14 @@
namespace blaze_util {
-using std::string;
-
extern const unsigned char kAsciiPropertyBits[256];
#define kApb kAsciiPropertyBits
static inline bool ascii_isspace(unsigned char c) { return kApb[c] & 0x08; }
-bool starts_with(const string &haystack, const string &needle);
+bool starts_with(const std::string &haystack, const std::string &needle);
-bool ends_with(const string &haystack, const string &needle);
+bool ends_with(const std::string &haystack, const std::string &needle);
// Matches a prefix (which must be a char* literal!) against the beginning of
// str. Returns a pointer past the prefix, or NULL if the prefix wasn't matched.
@@ -41,9 +39,10 @@ bool ends_with(const string &haystack, const string &needle);
//
// The ""'s catch people who don't pass in a literal for "prefix"
#ifndef strprefix
-#define strprefix(str, prefix) \
- (strncmp(str, prefix, sizeof("" prefix "")-1) == 0 ? \
- str + sizeof(prefix)-1 : NULL)
+#define strprefix(str, prefix) \
+ (strncmp(str, prefix, sizeof("" prefix "") - 1) == 0 \
+ ? str + sizeof(prefix) - 1 \
+ : NULL)
#endif
// Matches a prefix; returns a pointer past the prefix, or NULL if not found.
@@ -54,55 +53,57 @@ bool ends_with(const string &haystack, const string &needle);
// (Like strprefix() and strcaseprefix() but not restricted to searching for
// char* literals). Templated so searching a const char* returns a const char*,
// and searching a non-const char* returns a non-const char*.
-template<class CharStar>
-inline CharStar var_strprefix(CharStar str, const char* prefix) {
+template <class CharStar>
+inline CharStar var_strprefix(CharStar str, const char *prefix) {
const int len = strlen(prefix);
- return strncmp(str, prefix, len) == 0 ? str + len : NULL;
+ return strncmp(str, prefix, len) == 0 ? str + len : NULL;
}
// Returns a mutable char* pointing to a string's internal buffer, which may not
// be null-terminated. Returns NULL for an empty string. If not non-null,
// writing through this pointer will modify the string.
-inline char* string_as_array(string* str) {
+inline char *string_as_array(std::string *str) {
// DO NOT USE const_cast<char*>(str->data())! See the unittest for why.
return str->empty() ? NULL : &*str->begin();
}
// Join the elements of pieces separated by delimeter. Returns the joined
// string in output.
-void JoinStrings(
- const std::vector<string> &pieces, const char delimeter, string *output);
+void JoinStrings(const std::vector<std::string> &pieces, const char delimeter,
+ std::string *output);
// Splits contents by delimeter. Skips empty subsections.
-std::vector<string> Split(const string &contents, const char delimeter);
+std::vector<std::string> Split(const std::string &contents,
+ const char delimeter);
// Same as above, but adds results to output.
-void SplitStringUsing(
- const string &contents, const char delimeter, std::vector<string> *output);
+void SplitStringUsing(const std::string &contents, const char delimeter,
+ std::vector<std::string> *output);
// Same as above, but adds results to output. Returns number of elements added.
-size_t SplitQuotedStringUsing(const string &contents, const char delimeter,
- std::vector<string> *output);
+size_t SplitQuotedStringUsing(const std::string &contents, const char delimeter,
+ std::vector<std::string> *output);
// Global replace of oldsub with newsub.
-void Replace(const string &oldsub, const string &newsub, string *str);
+void Replace(const std::string &oldsub, const std::string &newsub,
+ std::string *str);
// Removes whitespace from both ends of a string.
-void StripWhitespace(string *str);
+void StripWhitespace(std::string *str);
// Tokenizes str on whitespace and places the tokens in words. Splits on spaces,
// newlines, carriage returns, and tabs. Respects single and double quotes (that
// is, "a string of 'some stuff'" would be 4 tokens). If the comment character
// is found (outside of quotes), the rest of the string will be ignored. Any
// token can be escaped with \, e.g., "this\\ is\\ one\\ token".
-void Tokenize(
- const string &str, const char &comment, std::vector<string> *words);
+void Tokenize(const std::string &str, const char &comment,
+ std::vector<std::string> *words);
// Evaluate a format string and store the result in 'str'.
-void StringPrintf(string *str, const char *format, ...);
+void StringPrintf(std::string *str, const char *format, ...);
// Convert str to lower case. No locale handling, this is just for ASCII.
-void ToLower(string* str);
+void ToLower(std::string *str);
} // namespace blaze_util