| 1021 | } |
| 1022 | } |
| 1023 | std::string ConvertToDBMSVer(const std::string& str) { |
| 1024 | boost::char_separator<char> separator("."); |
| 1025 | boost::tokenizer<boost::char_separator<char> > tokenizer(str, separator); |
| 1026 | std::string result; |
| 1027 | // The permitted ODBC format is ##.##.####<custom-server-information> |
| 1028 | // If any of the first 3 tokens are not numbers or are greater than the permitted |
| 1029 | // digits, assume we hit the custom-server-information early and assume the remaining |
| 1030 | // version digits are zero. |
| 1031 | size_t position = 0; |
| 1032 | bool is_showing_custom_data = false; |
| 1033 | auto pad_remaining_tokens = [&](size_t pos) -> std::string { |
| 1034 | std::string padded_str; |
| 1035 | if (pos == 0) { |
| 1036 | padded_str += "00"; |
| 1037 | } |
| 1038 | if (pos <= 1) { |
| 1039 | padded_str += ".00"; |
| 1040 | } |
| 1041 | if (pos <= 2) { |
| 1042 | padded_str += ".0000"; |
| 1043 | } |
| 1044 | return padded_str; |
| 1045 | }; |
| 1046 | |
| 1047 | for (auto token : tokenizer) { |
| 1048 | if (token.empty()) { |
| 1049 | continue; |
| 1050 | } |
| 1051 | |
| 1052 | if (!is_showing_custom_data && position < 3) { |
| 1053 | std::string suffix; |
| 1054 | try { |
| 1055 | size_t next_pos = 0; |
| 1056 | int version = stoi(token, &next_pos); |
| 1057 | if (next_pos != token.size()) { |
| 1058 | suffix = &token[0]; |
| 1059 | } |
| 1060 | if (version < 0 || (position < 2 && (version > 99)) || |
| 1061 | (position == 2 && version > 9999)) { |
| 1062 | is_showing_custom_data = true; |
| 1063 | } else { |
| 1064 | std::stringstream strstream; |
| 1065 | if (position == 2) { |
| 1066 | strstream << std::setfill('0') << std::setw(4); |
| 1067 | } else { |
| 1068 | strstream << std::setfill('0') << std::setw(2); |
| 1069 | } |
| 1070 | strstream << version; |
| 1071 | |
| 1072 | if (position != 0) { |
| 1073 | result += "."; |
| 1074 | } |
| 1075 | result += strstream.str(); |
| 1076 | if (next_pos != token.size()) { |
| 1077 | suffix = &token[next_pos]; |
| 1078 | result += pad_remaining_tokens(++position) + suffix; |
| 1079 | position = 4; // Prevent additional padding. |
| 1080 | is_showing_custom_data = true; |