interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / patch / p2utf8.om
| 1 | note patch/p2utf8.om: the text rules of a title and a description (docs/collab-write.md section 2), |
| 2 | note over the decoded field gpfv. The same code as collab/co9comp.om cowutf8, coctlok and coulen under |
| 3 | note this slice's names: the store-reading build composes collab out (server/nocollab.om), so the |
| 4 | note patch intake carries its own copy and needs no collab unit. |
| 5 | note pawutf8 n ml: well-formed UTF-8 (no overlong forms, surrogates or code points over U+10FFFF), no |
| 6 | note NUL, C0 control or DEL byte except tab and LF when ml |
| 7 | fn pawutf8 n ulong ml bool to bool |
| 8 | i = ulong 0 |
| 9 | while lt i n bound 70000 |
| 10 | c = get gpfv i |
| 11 | if lt c 128 |
| 12 | if eq pactlok c ml false |
| 13 | ret false |
| 14 | end |
| 15 | i = add i 1 |
| 16 | else |
| 17 | k = paulen i n |
| 18 | if eq k 0 |
| 19 | ret false |
| 20 | end |
| 21 | i = add i k |
| 22 | end |
| 23 | end |
| 24 | ret true |
| 25 | end |
| 26 | fn pactlok c uchar ml bool to bool |
| 27 | if eq c 127 |
| 28 | ret false |
| 29 | end |
| 30 | if ge c 32 |
| 31 | ret true |
| 32 | end |
| 33 | if and ml or eq c 9 eq c 10 |
| 34 | ret true |
| 35 | end |
| 36 | ret false |
| 37 | end |
| 38 | note paulen i n: byte length of the multi-byte sequence at gpfv[i], 0 when it is malformed |
| 39 | fn paulen i ulong n ulong to ulong |
| 40 | c = get gpfv i |
| 41 | k = ulong 0 |
| 42 | lo = uchar 128 |
| 43 | hi = uchar 191 |
| 44 | if and ge c 194 le c 223 |
| 45 | k = ulong 2 |
| 46 | end |
| 47 | if and ge c 224 le c 239 |
| 48 | k = ulong 3 |
| 49 | if eq c 224 |
| 50 | lo = uchar 160 |
| 51 | end |
| 52 | if eq c 237 |
| 53 | hi = uchar 159 |
| 54 | end |
| 55 | end |
| 56 | if and ge c 240 le c 244 |
| 57 | k = ulong 4 |
| 58 | if eq c 240 |
| 59 | lo = uchar 144 |
| 60 | end |
| 61 | if eq c 244 |
| 62 | hi = uchar 143 |
| 63 | end |
| 64 | end |
| 65 | if or eq k 0 gt add i k n |
| 66 | ret ulong 0 |
| 67 | end |
| 68 | d = get gpfv add i 1 |
| 69 | if or lt d lo gt d hi |
| 70 | ret ulong 0 |
| 71 | end |
| 72 | for j ulong sub k 2 bound 2 |
| 73 | d = get gpfv add add i 2 j |
| 74 | if or lt d 128 gt d 191 |
| 75 | ret ulong 0 |
| 76 | end |
| 77 | end |
| 78 | ret k |
| 79 | end |