* Validates and converts format to the strptime equivalent * */
| 53 | * |
| 54 | */ |
| 55 | Status DateUtils::ToInternalFormat(const std::string& format, |
| 56 | std::shared_ptr<std::string>* internal_format) { |
| 57 | std::stringstream builder; |
| 58 | std::stringstream buffer; |
| 59 | bool is_in_quoted_text = false; |
| 60 | |
| 61 | for (size_t i = 0; i < format.size(); i++) { |
| 62 | char currentChar = format[i]; |
| 63 | |
| 64 | // logic before we append to the buffer |
| 65 | if (currentChar == '"') { |
| 66 | if (is_in_quoted_text) { |
| 67 | // we are done with a quoted block |
| 68 | is_in_quoted_text = false; |
| 69 | |
| 70 | // use ' for quoting |
| 71 | builder << '\''; |
| 72 | builder << buffer.str(); |
| 73 | builder << '\''; |
| 74 | |
| 75 | // clear buffer |
| 76 | buffer.str(""); |
| 77 | continue; |
| 78 | } else { |
| 79 | ARROW_RETURN_IF(buffer.str().length() > 0, |
| 80 | Status::Invalid("Invalid date format string '", format, "'")); |
| 81 | |
| 82 | is_in_quoted_text = true; |
| 83 | continue; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // handle special characters we want to simply pass through, but only if not in quoted |
| 88 | // and the buffer is empty |
| 89 | std::string special_characters = "*-/,.;: "; |
| 90 | if (!is_in_quoted_text && buffer.str().length() == 0 && |
| 91 | (special_characters.find_first_of(currentChar) != std::string::npos)) { |
| 92 | builder << currentChar; |
| 93 | continue; |
| 94 | } |
| 95 | |
| 96 | // append to the buffer |
| 97 | buffer << currentChar; |
| 98 | |
| 99 | // nothing else to do if we are in quoted text |
| 100 | if (is_in_quoted_text) { |
| 101 | continue; |
| 102 | } |
| 103 | |
| 104 | // check how many matches we have for our buffer |
| 105 | std::vector<std::string> potentialList = GetPotentialMatches(buffer.str()); |
| 106 | int64_t potentialCount = potentialList.size(); |
| 107 | |
| 108 | if (potentialCount >= 1) { |
| 109 | // one potential and the length match |
| 110 | if (potentialCount == 1 && potentialList[0].length() == buffer.str().length()) { |
| 111 | // we have a match! |
| 112 | builder << sql_date_format_to_boost_map_[potentialList[0]]; |