{ "z", 1e-21L },
{ "y", 1e-24L },
{ " ", 0 },
- { 0, 0}
+ { 0, 0}
};
const PrettySuffix* const kPrettySuffixes[PRETTY_NUM_TYPES] = {
//TODO:
//1) Benchmark & optimize
-double prettyToDouble(folly::StringPiece *const prettyString,
+double prettyToDouble(folly::StringPiece *const prettyString,
const PrettyType type) {
double value = folly::to<double>(prettyString);
while (prettyString->size() > 0 && std::isspace(prettyString->front())) {
prettyString->toString(), "\""));
}
prettyString->advance(longestPrefixLen);
- return suffixes[bestPrefixId].val ? value * suffixes[bestPrefixId].val :
+ return suffixes[bestPrefixId].val ? value * suffixes[bestPrefixId].val :
value;
}
double prettyToDouble(folly::StringPiece prettyString, const PrettyType type){
double result = prettyToDouble(&prettyString, type);
- detail::enforceWhitespace(prettyString.data(),
+ detail::enforceWhitespace(prettyString.data(),
prettyString.data() + prettyString.size());
return result;
}
return result;
}
+StringPiece skipWhitespace(StringPiece sp) {
+ // Spaces other than ' ' characters are less common but should be
+ // checked. This configuration where we loop on the ' '
+ // separately from oddspaces was empirically fastest.
+ auto oddspace = [] (char c) {
+ return c == '\n' || c == '\t' || c == '\r';
+ };
+
+loop:
+ for (; !sp.empty() && sp.front() == ' '; sp.pop_front()) {
+ }
+ if (!sp.empty() && oddspace(sp.front())) {
+ sp.pop_front();
+ goto loop;
+ }
+
+ return sp;
+}
+
namespace detail {
size_t hexDumpLine(const void* ptr, size_t offset, size_t size,
# undef DMGL_TYPES
# undef DMGL_RET_POSTFIX
#endif
-
return output;
}
+/**
+ * Returns a subpiece with all whitespace removed from the front of @sp.
+ * Whitespace means any of [' ', '\n', '\r', '\t'].
+ */
+StringPiece skipWhitespace(StringPiece sp);
+
} // namespace folly
// Hash functions to make std::string usable with e.g. hash_map
#include <boost/next_prior.hpp>
#include <boost/algorithm/string.hpp>
+#include <folly/Conv.h>
#include <folly/Range.h>
+#include <folly/String.h>
#include <folly/Unicode.h>
-#include <folly/Conv.h>
namespace folly {
}
void skipWhitespace() {
- // Spaces other than ' ' characters are less common but should be
- // checked. This configuration where we loop on the ' '
- // separately from oddspaces was empirically fastest.
- auto oddspace = [] (char c) {
- return c == '\n' || c == '\t' || c == '\r';
- };
-
- loop:
- for (; !range_.empty() && range_.front() == ' '; range_.pop_front()) {
- }
- if (!range_.empty() && oddspace(range_.front())) {
- range_.pop_front();
- goto loop;
- }
+ range_ = folly::skipWhitespace(range_);
storeCurrent();
}