-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The 'd' in [red] is interpreted as a date format #388
Comments
@nacnudus I hate to be that person, but there are other colors to consider. The valid colors are Black, Green, White, Blue, Magenta, Yellow, Cyan, and Red, and they can appear with lowercase characters. The other cases are fairly obvious: https://jsfiddle.net/w7veddw9/1/ will generate a file Other cases to consider:
If you really want a fun case, the format Putting that all together, the correct date check would look something like: /* TODO: actually validate that the format is valid */
#define CASEI(c) case c: case c | 0x20
#define CMPLC(i,n) if(x[i+i] | 0x20 == n)
inline bool isDateFormat(std::string x) {
char escaped = 0, bracket = 0;
for (size_t i = 0; i < x.size(); ++i) switch (x[i]) {
CASEI('D'):
CASEI('E'):
CASEI('H'):
CASEI('M'):
CASEI('S'):
CASEI('Y'):
if(!escaped && !bracket) return true;
break;
case '"':
escaped = 1 - escaped; break;
case '\\': ++i; break;
case '[': if(!escaped) bracket = 1; break;
case ']': if(!escaped) bracket = 0; break;
CASEI('G'):
if(i + 6 < x.size())
CMPLC(1,'e')
CMPLC(2,'n')
CMPLC(3,'e')
CMPLC(4,'r')
CMPLC(5,'a')
CMPLC(6,'l')
return false;
}
return false;
}
#undef CMPLC
#undef CASEI |
@reviewher That is really helpful, thank you for being 'that person'! I didn't know about all-lowercase names, but to miss |
It was too crude before. Thanks to @reviewher tidyverse/readxl#388 for providing info and code.
It turns out underscores should be treated as escape characters too. See also ECMA-376-1:2016 page 1785 (actual page 1795) section 18.8.31 "numFmts (Number Formats)"
case '\\':
case '_':
++i;
break; |
* Don't misinterpret colors as dates (fixes #388) * Incorporate some updates * Add a test; tweak some tests Add a test and test file based on a format where the confusion can come via currency, not colour. Link to issues. We generally incorporate `-xls` or `-xlsx` into test file names, so the format is obvious even if the file is open in Excel. Added the actual implicit number formats in comments. Co-authored-by: Jenny Bryan <jenny.f.bryan@gmail.com>
readxl/src/ColSpec.h
Lines 145 to 148 in 0d9ad4f
That was too tempting for somebody, who created this beauty (see
MedicareAndLevies!Q:Q
):How to fix?
readxl/src/ColSpec.h
Line 150 in 0d9ad4f
... like the awful hack in tidyxl? 😉
Reprex:
The culpable number formats:
Kudos to @HughParsonage for discovering this file and daring to import it into R.
The text was updated successfully, but these errors were encountered: