Appearance
| 1 | namespace Semantic.DotNet is | |
| 2 | use Collections | |
| 3 | ||
| 4 | // The ilasm textual forms for custom-attribute arguments — the | |
| 5 | // `{ ... }` body of a `.custom` directive. ilasm encodes the blob | |
| 6 | // from these, so the prolog, the compressed length prefixes and the | |
| 7 | // trailing named-argument count are all its responsibility rather | |
| 8 | // than the caller's. | |
| 9 | // | |
| 10 | // A string carrying a NUL cannot be expressed: ilasm holds a quoted | |
| 11 | // literal as a NUL-terminated string and silently drops everything | |
| 12 | // from the NUL onwards. | |
| 13 | class IL_ATTRIBUTE_ARGUMENTS is | |
| 14 | // Wraps `value` in the ilasm single-quoted form, escaping the | |
| 15 | // delimiter, the escape character itself, and the whitespace that | |
| 16 | // a quoted literal cannot carry raw. | |
| 17 | quote(value: string) -> string static is | |
| 18 | let buffer = System.Text.StringBuilder() | |
| 19 | ||
| 20 | buffer.append("'") | |
| 21 | ||
| 22 | for c in value do | |
| 23 | if c == '\\' then | |
| 24 | buffer.append("\\\\") | |
| 25 | elif c == '\'' then | |
| 26 | buffer.append("\\'") | |
| 27 | elif c == '\n' then | |
| 28 | buffer.append("\\n") | |
| 29 | elif c == '\r' then | |
| 30 | buffer.append("\\r") | |
| 31 | elif c == '\t' then | |
| 32 | buffer.append("\\t") | |
| 33 | else | |
| 34 | buffer.append(c) | |
| 35 | fi | |
| 36 | od | |
| 37 | ||
| 38 | buffer.append("'") | |
| 39 | ||
| 40 | return buffer.to_string() | |
| 41 | si | |
| 42 | si | |
| 43 | si |