Create ParseDataType unit tests based on specs.
Test cases that are commented out are failing with our current
implementation.
Change-Id: I9f80003af5a5d182f53cc655454aec44397d278b
Reviewed-on: https://pdfium-review.googlesource.com/7890
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp
index 3338a3a..7f0fe1e 100644
--- a/fpdfsdk/javascript/util.cpp
+++ b/fpdfsdk/javascript/util.cpp
@@ -70,40 +70,6 @@
#endif
};
-int ParseDataType(std::wstring* sFormat) {
- bool bPercent = false;
- for (size_t i = 0; i < sFormat->length(); ++i) {
- wchar_t c = (*sFormat)[i];
- if (c == L'%') {
- bPercent = true;
- continue;
- }
-
- if (bPercent) {
- if (c == L'c' || c == L'C' || c == L'd' || c == L'i' || c == L'o' ||
- c == L'u' || c == L'x' || c == L'X') {
- return UTIL_INT;
- }
- if (c == L'e' || c == L'E' || c == L'f' || c == L'g' || c == L'G') {
- return UTIL_DOUBLE;
- }
- if (c == L's' || c == L'S') {
- // Map s to S since we always deal internally
- // with wchar_t strings.
- (*sFormat)[i] = L'S';
- return UTIL_STRING;
- }
- if (c == L'.' || c == L'+' || c == L'-' || c == L'#' || c == L' ' ||
- std::iswdigit(c)) {
- continue;
- }
- break;
- }
- }
-
- return -1;
-}
-
} // namespace
util::util(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {}
@@ -480,3 +446,37 @@
vRet = CJS_Value(pRuntime, wStr.c_str());
return true;
}
+
+int util::ParseDataType(std::wstring* sFormat) {
+ bool bPercent = false;
+ for (size_t i = 0; i < sFormat->length(); ++i) {
+ wchar_t c = (*sFormat)[i];
+ if (c == L'%') {
+ bPercent = true;
+ continue;
+ }
+
+ if (bPercent) {
+ if (c == L'c' || c == L'C' || c == L'd' || c == L'i' || c == L'o' ||
+ c == L'u' || c == L'x' || c == L'X') {
+ return UTIL_INT;
+ }
+ if (c == L'e' || c == L'E' || c == L'f' || c == L'g' || c == L'G') {
+ return UTIL_DOUBLE;
+ }
+ if (c == L's' || c == L'S') {
+ // Map s to S since we always deal internally
+ // with wchar_t strings.
+ (*sFormat)[i] = L'S';
+ return UTIL_STRING;
+ }
+ if (c == L'.' || c == L'+' || c == L'-' || c == L'#' || c == L' ' ||
+ std::iswdigit(c)) {
+ continue;
+ }
+ break;
+ }
+ }
+
+ return -1;
+}