| 1881 | } |
| 1882 | |
| 1883 | StringRef ScalarNode::getValue(SmallVectorImpl<char> &Storage) const { |
| 1884 | // TODO: Handle newlines properly. We need to remove leading whitespace. |
| 1885 | if (Value[0] == '"') { // Double quoted. |
| 1886 | // Pull off the leading and trailing "s. |
| 1887 | StringRef UnquotedValue = Value.substr(1, Value.size() - 2); |
| 1888 | // Search for characters that would require unescaping the value. |
| 1889 | StringRef::size_type i = UnquotedValue.find_first_of("\\\r\n"); |
| 1890 | if (i != StringRef::npos) |
| 1891 | return unescapeDoubleQuoted(UnquotedValue, i, Storage); |
| 1892 | return UnquotedValue; |
| 1893 | } else if (Value[0] == '\'') { // Single quoted. |
| 1894 | // Pull off the leading and trailing 's. |
| 1895 | StringRef UnquotedValue = Value.substr(1, Value.size() - 2); |
| 1896 | StringRef::size_type i = UnquotedValue.find('\''); |
| 1897 | if (i != StringRef::npos) { |
| 1898 | // We're going to need Storage. |
| 1899 | Storage.clear(); |
| 1900 | Storage.reserve(UnquotedValue.size()); |
| 1901 | for (; i != StringRef::npos; i = UnquotedValue.find('\'')) { |
| 1902 | StringRef Valid(UnquotedValue.begin(), i); |
| 1903 | Storage.insert(Storage.end(), Valid.begin(), Valid.end()); |
| 1904 | Storage.push_back('\''); |
| 1905 | UnquotedValue = UnquotedValue.substr(i + 2); |
| 1906 | } |
| 1907 | Storage.insert(Storage.end(), UnquotedValue.begin(), UnquotedValue.end()); |
| 1908 | return StringRef(Storage.begin(), Storage.size()); |
| 1909 | } |
| 1910 | return UnquotedValue; |
| 1911 | } |
| 1912 | // Plain or block. |
| 1913 | return Value.rtrim(' '); |
| 1914 | } |
| 1915 | |
| 1916 | StringRef ScalarNode::unescapeDoubleQuoted( StringRef UnquotedValue |
| 1917 | , StringRef::size_type i |
no test coverage detected