nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: Added contributing guidelines and link from readme
[nit.git]
/
lib
/
core
/
text
/
flat.nit
diff --git
a/lib/core/text/flat.nit
b/lib/core/text/flat.nit
index
67ffacf
..
6273609
100644
(file)
--- a/
lib/core/text/flat.nit
+++ b/
lib/core/text/flat.nit
@@
-225,6
+225,22
@@
redef class FlatText
req_esc += 1
else if c == 0x5Cu8 then
req_esc += 1
req_esc += 1
else if c == 0x5Cu8 then
req_esc += 1
+ else if c == 0x3Fu8 then
+ var j = pos + 1
+ if j < length then
+ var next = its[j]
+ # We ignore `??'` because it will be escaped as `??\'`.
+ if
+ next == 0x21u8 or
+ next == 0x28u8 or
+ next == 0x29u8 or
+ next == 0x2Du8 or
+ next == 0x2Fu8 or
+ next == 0x3Cu8 or
+ next == 0x3Du8 or
+ next == 0x3Eu8
+ then req_esc += 1
+ end
else if c < 32u8 then
req_esc += 3
end
else if c < 32u8 then
req_esc += 3
end
@@
-280,6
+296,27
@@
redef class FlatText
nns[opos] = 0x5Cu8
nns[opos + 1] = 0x5Cu8
opos += 2
nns[opos] = 0x5Cu8
nns[opos + 1] = 0x5Cu8
opos += 2
+ else if c == 0x3Fu8 then
+ var j = pos + 1
+ if j < length then
+ var next = its[j]
+ # We ignore `??'` because it will be escaped as `??\'`.
+ if
+ next == 0x21u8 or
+ next == 0x28u8 or
+ next == 0x29u8 or
+ next == 0x2Du8 or
+ next == 0x2Fu8 or
+ next == 0x3Cu8 or
+ next == 0x3Du8 or
+ next == 0x3Eu8
+ then
+ nns[opos] = 0x5Cu8
+ opos += 1
+ end
+ end
+ nns[opos] = 0x3Fu8
+ opos += 1
else if c < 32u8 then
nns[opos] = 0x5Cu8
nns[opos + 1] = 0x30u8
else if c < 32u8 then
nns[opos] = 0x5Cu8
nns[opos + 1] = 0x30u8
@@
-369,6
+406,10
@@
redef class FlatText
end
return res
end
end
return res
end
+
+ redef fun copy_to_native(dst, n, src_off, dst_off) do
+ _items.copy_to(dst, n, first_byte + src_off, dst_off)
+ end
end
# Immutable strings of characters.
end
# Immutable strings of characters.
@@
-666,15
+707,15
@@
private class ASCIIFlatString
end
redef fun substring(from, count) do
end
redef fun substring(from, count) do
+ var ln = _length
+ if count <= 0 then return ""
+ if (count + from) > ln then count = ln - from
if count <= 0 then return ""
if count <= 0 then return ""
-
if from < 0 then
count += from
if from < 0 then
count += from
- if count < 0 then return ""
+ if count <= 0 then return ""
from = 0
end
from = 0
end
- var ln = _length
- if (count + from) > ln then count = ln - from
return new ASCIIFlatString.full_data(_items, count, from + _first_byte, count)
end
return new ASCIIFlatString.full_data(_items, count, from + _first_byte, count)
end
@@
-924,7
+965,10
@@
class FlatBuffer
is_dirty = true
_bytelen = 0
_length = 0
is_dirty = true
_bytelen = 0
_length = 0
- if written then reset
+ if written then
+ _capacity = 16
+ reset
+ end
end
redef fun empty do return new Buffer
end
redef fun empty do return new Buffer
@@
-991,15
+1035,10
@@
class FlatBuffer
init from(s: Text)
do
_items = new NativeString(s.bytelen)
init from(s: Text)
do
_items = new NativeString(s.bytelen)
- if s isa FlatText then
- _items = s._items
- else
- for i in substrings do i.as(FlatString)._items.copy_to(_items, i._bytelen, 0, 0)
- end
+ for i in s.substrings do i._items.copy_to(_items, i._bytelen, first_byte, 0)
_bytelen = s.bytelen
_length = s.length
_capacity = _bytelen
_bytelen = s.bytelen
_length = s.length
_capacity = _bytelen
- written = true
end
# Create a new empty string with a given capacity.
end
# Create a new empty string with a given capacity.