| 8014 | |
| 8015 | |
| 8016 | ResultType ConvertFileOptions(ResultToken &aResultToken, LPTSTR aOptions, UINT &codepage, bool &translate_crlf_to_lf, unsigned __int64 *pmax_bytes_to_load) |
| 8017 | { |
| 8018 | for (LPTSTR next, cp = aOptions; cp && *(cp = omit_leading_whitespace(cp)); cp = next) |
| 8019 | { |
| 8020 | if (*cp == '\n') |
| 8021 | { |
| 8022 | translate_crlf_to_lf = true; |
| 8023 | // Rather than treating "`nxxx" as invalid or ignoring "xxx", let the delimiter be |
| 8024 | // optional for `n. Treating "`nxxx" and "m1024`n" and "utf-8`n" as invalid would |
| 8025 | // require larger code, and would produce confusing error messages because the `n |
| 8026 | // isn't visible; e.g. "Invalid option. Specifically: utf-8" |
| 8027 | next = cp + 1; |
| 8028 | continue; |
| 8029 | } |
| 8030 | // \n is included below to allow "m1024`n" and "utf-8`n" (see above). |
| 8031 | next = StrChrAny(cp, _T(" \t\n")); |
| 8032 | |
| 8033 | switch (ctoupper(*cp)) |
| 8034 | { |
| 8035 | case 'M': |
| 8036 | if (pmax_bytes_to_load) // i.e. caller is FileRead. |
| 8037 | { |
| 8038 | *pmax_bytes_to_load = ATOU64(cp + 1); // Relies upon the fact that it ceases conversion upon reaching a space or tab. |
| 8039 | break; |
| 8040 | } |
| 8041 | // Otherwise, fall through to treat it as invalid: |
| 8042 | default: |
| 8043 | TCHAR name[12]; // Large enough for any valid encoding. |
| 8044 | if (next && (next - cp) < _countof(name)) |
| 8045 | { |
| 8046 | // Create a temporary null-terminated copy. |
| 8047 | wmemcpy(name, cp, next - cp); |
| 8048 | name[next - cp] = '\0'; |
| 8049 | cp = name; |
| 8050 | } |
| 8051 | if (!_tcsicmp(cp, _T("RAW"))) |
| 8052 | { |
| 8053 | codepage = -1; |
| 8054 | } |
| 8055 | else |
| 8056 | { |
| 8057 | codepage = Line::ConvertFileEncoding(cp); |
| 8058 | if (codepage == -1 || cisdigit(*cp)) // Require "cp" prefix in FileRead/FileAppend options. |
| 8059 | return aResultToken.ValueError(ERR_INVALID_OPTION, cp); |
| 8060 | } |
| 8061 | break; |
| 8062 | } // switch() |
| 8063 | } // for() |
| 8064 | return OK; |
| 8065 | } |
| 8066 | |
| 8067 | BIF_DECL(BIF_FileRead) |
| 8068 | { |
no test coverage detected