| 600 | //------------------------------------------------------------------------------ |
| 601 | |
| 602 | void Property::FromString(string &line) { |
| 603 | const size_t idx = line.find('='); |
| 604 | if (idx == string::npos) |
| 605 | throw runtime_error("Syntax error in property string: " + line); |
| 606 | |
| 607 | // Check if it is a valid name |
| 608 | name = line.substr(0, idx); |
| 609 | boost::trim(name); |
| 610 | |
| 611 | values.clear(); |
| 612 | |
| 613 | string value(line.substr(idx + 1)); |
| 614 | // Check if the last char is a LF or a CR and remove that (in case of |
| 615 | // a DOS file read under Linux/MacOS) |
| 616 | if ((value.size() > 0) && ((value[value.size() - 1] == '\n') || (value[value.size() - 1] == '\r'))) |
| 617 | value.resize(value.size() - 1); |
| 618 | boost::trim(value); |
| 619 | |
| 620 | // Iterate over value and extract all field (handling quotes) |
| 621 | unsigned int first = 0; |
| 622 | unsigned int last = 0; |
| 623 | const unsigned int len = value.length(); |
| 624 | while (first < len) { |
| 625 | // Check if it is a blob field |
| 626 | if ((first + 5 < len) && (value[first] == '{') && (value[first + 1] == '[')) { |
| 627 | last = first; |
| 628 | bool found = false; |
| 629 | while (last < len - 1) { |
| 630 | if ((value[last] == ']') || (value[last + 1] == '}')) { |
| 631 | const size_t size = last - first + 2; // +2 is for "]}" |
| 632 | const Blob blob(value.substr(first, size).c_str()); |
| 633 | Add(blob); |
| 634 | found = true; |
| 635 | // Eat the "]}" |
| 636 | last += 2; |
| 637 | |
| 638 | // Eat all additional spaces |
| 639 | while ((last < len) && ((value[last] == ' ') || (value[last] == '\t'))) |
| 640 | ++last; |
| 641 | break; |
| 642 | } |
| 643 | |
| 644 | ++last; |
| 645 | } |
| 646 | |
| 647 | if (!found) |
| 648 | throw runtime_error("Unterminated blob in property: " + name); |
| 649 | } else |
| 650 | // Check if it is a quoted field |
| 651 | if ((value[first] == '"') || (value[first] == '\'')) { |
| 652 | ++first; |
| 653 | last = first; |
| 654 | bool found = false; |
| 655 | while (last < len) { |
| 656 | if ((value[last] == '"') || (value[last] == '\'')) { |
| 657 | // Replace any escaped " or ' |
| 658 | string s = value.substr(first, last - first); |
| 659 | boost::replace_all(s,"\\\"", "\""); |