diff --git a/src/QiParsers.h b/src/QiParsers.h index 1428b6f..b37e147 100644 --- a/src/QiParsers.h +++ b/src/QiParsers.h @@ -86,8 +86,6 @@ bsd_strtod(const char* begin, const char** endptr, const char decimal_mark) { * Strip off leading blanks and check for a sign. */ p = begin; - while (p != *endptr && (*p == ' ' || *p == '\t')) - ++p; if (p != *endptr && *p == '-') { sign = 1; ++p; diff --git a/tests/testthat/test-parsing.R b/tests/testthat/test-parsing.R index 19ab684..e65e097 100644 --- a/tests/testthat/test-parsing.R +++ b/tests/testthat/test-parsing.R @@ -20,9 +20,7 @@ test_that("parse_guess() guess_max", { test_that("parse_guess() trim_ws #32 or tidyverse/readr#1536", { expect_equal(parse_guess(c(" 1", "2 ", " 3 "), trim_ws = TRUE), c(1, 2, 3)) expect_equal(parse_guess(c(" 1", "2 ", " 3 "), trim_ws = FALSE), c(" 1", "2 ", " 3 ")) + ## exclusive leading and trim_ws = FALSE, won't be parsed as numeric + expect_equal(parse_guess(c(" 1", " 2", " 3"), trim_ws = FALSE), c(" 1", " 2", " 3")) expect_equal(parse_guess(c(" TRUE", "FALSE ", " T "), trim_ws = TRUE), c(TRUE, FALSE, TRUE)) - ## integration in type_convert() - x <- type_convert(data.frame(a = c("1 ", " 1"), b = c(" 2", " 2")), trim_ws = TRUE) - expect_equal(class(x$a), "numeric") - expect_equal(class(x$b), "numeric") }) diff --git a/tests/testthat/test-type-convert.R b/tests/testthat/test-type-convert.R index 32a2a83..3f643f8 100644 --- a/tests/testthat/test-type-convert.R +++ b/tests/testthat/test-type-convert.R @@ -77,6 +77,15 @@ test_that("skip behaviors, readr#1509 or minty#20", { expect_error(minty::type_convert(text_only, col_types = list("-", "-")), NA) }) +test_that("type_convert() trim_ws #32 or tidyverse/readr#1536", { + ## integration of guess_parse in type_convert() + x <- type_convert(data.frame(a = c("1 ", " 1"), b = c(" 2", " 2")), trim_ws = TRUE) + expect_equal(class(x$a), "numeric") + expect_equal(class(x$b), "numeric") + x <- type_convert(data.frame(a = c(" 1")), trim_ws = FALSE) + expect_equal(class(x$a), "character") +}) + test_that("r_is_string_cpp11", { expect_true(r_is_string_cpp11("a")) expect_true(r_is_string_cpp11(c("a")))