1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
11 # All the array-based text representations
14 intrude import abstract_text
22 private class FlatSubstringsIter
23 super Iterator[FlatText]
25 var tgt
: nullable FlatText
29 return tgt
.as(not null)
32 redef fun is_ok
do return tgt
!= null
34 redef fun next
do tgt
= null
39 private fun first_byte
: Int do return 0
41 private fun last_byte
: Int do return _bytelen
- 1
43 # Cache of the latest position (char) explored in the string
44 private var position
: Int = 0
46 # Cached position (bytes) in the NativeString underlying the String
47 private var bytepos
: Int = 0
49 # Index of the character `index` in `_items`
50 private fun char_to_byte_index
(index
: Int): Int do
56 # Find best insertion point
57 var delta_begin
= index
58 var delta_end
= (ln
- 1) - index
59 var delta_cache
= (pos
- index
).abs
63 if delta_cache
< min
then min
= delta_cache
64 if delta_end
< min
then min
= delta_end
69 if min
== delta_begin
then
72 else if min
== delta_cache
then
76 ns_i
= its
.find_beginning_of_char_at
(last_byte
)
80 ns_i
= its
.char_to_byte_index_cached
(index
, my_i
, ns_i
)
88 # By escaping `self` to C, how many more bytes will be needed ?
90 # This enables a double-optimization in `escape_to_c` since if this
91 # method returns 0, then `self` does not need escaping and can be
93 protected fun chars_to_escape_to_c
: Int do
102 else if c
== 0x09u
8 then
104 else if c
== 0x22u
8 then
106 else if c
== 0x27u
8 then
108 else if c
== 0x5Cu
8 then
110 else if c
< 32u8
then
118 redef fun escape_to_c
do
119 var ln_extra
= chars_to_escape_to_c
120 if ln_extra
== 0 then return self.to_s
123 var nlen
= _bytelen
+ ln_extra
124 var nns
= new NativeString(nlen
)
131 # Any byte with value < 32 is a control character
132 # All their uses will be replaced by their octal
135 # There are two exceptions however:
140 # Aside from the code points above, the following are:
147 nns
[opos
+ 1] = 0x74u
8
149 else if c
== 0x0Au
8 then
151 nns
[opos
+ 1] = 0x6Eu
8
153 else if c
== 0x22u
8 then
155 nns
[opos
+ 1] = 0x22u
8
157 else if c
== 0x27u
8 then
159 nns
[opos
+ 1] = 0x27u
8
161 else if c
== 0x5Cu
8 then
163 nns
[opos
+ 1] = 0x5Cu
8
165 else if c
< 32u8
then
167 nns
[opos
+ 1] = 0x30u
8
168 nns
[opos
+ 2] = ((c
& 0x38u
8) >> 3) + 0x30u
8
169 nns
[opos
+ 3] = (c
& 0x07u
8) + 0x30u
8
177 return nns
.to_s_with_length
(nlen
)
180 redef fun [](index
) do return _items
.char_at
(char_to_byte_index
(index
))
183 # Immutable strings of characters.
188 # Index at which `self` begins in `_items`, inclusively
189 redef var first_byte
is noinit
191 # Index at which `self` ends in `_items`, inclusively
192 redef var last_byte
is noinit
194 redef var chars
= new FlatStringCharView(self) is lazy
196 redef var bytes
= new FlatStringByteView(self) is lazy
198 redef var length
is lazy
do
199 if _bytelen
== 0 then return 0
200 return _items
.utf8_length
(_first_byte
, _last_byte
)
203 redef var to_cstring
is lazy
do
205 var new_items
= new NativeString(blen
+ 1)
206 _items
.copy_to
(new_items
, blen
, _first_byte
, 0)
207 new_items
[blen
] = 0u8
213 var b
= new FlatBuffer.with_capacity
(_bytelen
+ 1)
214 for i
in [length
- 1 .. 0].step
(-1) do
217 var s
= b
.to_s
.as(FlatString)
218 s
.length
= self.length
222 redef fun fast_cstring
do return _items
.fast_cstring
(_first_byte
)
224 redef fun substring
(from
, count
)
230 if count
< 0 then count
= 0
234 if (count
+ from
) > length
then count
= length
- from
235 if count
<= 0 then return ""
236 var end_index
= from
+ count
- 1
238 var bytefrom
= char_to_byte_index
(from
)
239 var byteto
= char_to_byte_index
(end_index
)
241 byteto
+= its
.length_of_char_at
(byteto
) - 1
243 var s
= new FlatString.full
(its
, byteto
- bytefrom
+ 1, bytefrom
, byteto
, count
)
247 redef fun empty
do return "".as(FlatString)
251 var outstr
= new FlatBuffer.with_capacity
(self._bytelen
+ 1)
257 outstr
.add
(chars
[pos
].to_upper
)
266 var outstr
= new FlatBuffer.with_capacity
(self._bytelen
+ 1)
272 outstr
.add
(chars
[pos
].to_lower
)
281 for i
in chars
do i
.output
284 ##################################################
285 # String Specific Methods #
286 ##################################################
288 # Low-level creation of a new string with minimal data.
290 # `_items` will be used as is, without copy, to retrieve the characters of the string.
291 # Aliasing issues is the responsibility of the caller.
292 private init with_infos
(items
: NativeString, bytelen
, from
, to
: Int)
295 self._bytelen
= bytelen
301 # Low-level creation of a new string with all the data.
303 # `_items` will be used as is, without copy, to retrieve the characters of the string.
304 # Aliasing issues is the responsibility of the caller.
305 private init full
(items
: NativeString, bytelen
, from
, to
, length
: Int)
309 self._bytelen
= bytelen
317 if not other
isa FlatString then return super
319 if self.object_id
== other
.object_id
then return true
321 var my_length
= _bytelen
323 if other
._bytelen
!= my_length
then return false
325 var my_index
= _first_byte
326 var its_index
= other
._first_byte
328 var last_iteration
= my_index
+ my_length
330 var its_items
= other
._items
331 var my_items
= self._items
333 while my_index
< last_iteration
do
334 if my_items
[my_index
] != its_items
[its_index
] then return false
344 if not other
isa FlatString then return super
346 if self.object_id
== other
.object_id
then return false
348 var my_length
= self._bytelen
349 var its_length
= other
._bytelen
351 var max
= if my_length
< its_length
then my_length
else its_length
353 var myits
= self.bytes
354 var itsits
= other
.bytes
356 for i
in [0 .. max
[ do
357 var my_curr_char
= myits
[i
]
358 var its_curr_char
= itsits
[i
]
360 if my_curr_char
!= its_curr_char
then
361 if my_curr_char
< its_curr_char
then return true
366 return my_length
< its_length
373 var nlen
= mlen
+ slen
375 var mifrom
= _first_byte
376 if s
isa FlatText then
378 var sifrom
= s
.first_byte
379 var ns
= new NativeString(nlen
+ 1)
380 mits
.copy_to
(ns
, mlen
, mifrom
, 0)
381 sits
.copy_to
(ns
, slen
, sifrom
, mlen
)
382 return new FlatString.full
(ns
, nlen
, 0, nlen
- 1, length
+ o
.length
)
389 var mybtlen
= _bytelen
390 var new_bytelen
= mybtlen
* i
392 var newlen
= mylen
* i
395 var ns
= new NativeString(new_bytelen
+ 1)
396 ns
[new_bytelen
] = 0u8
399 its
.copy_to
(ns
, mybtlen
, fb
, offset
)
403 return new FlatString.full
(ns
, new_bytelen
, 0, new_bytelen
- 1, newlen
)
409 if hash_cache
== null then
410 # djb2 hash algorithm
414 var my_items
= _items
418 h
= (h
<< 5) + h
+ my_items
[i
].to_i
425 return hash_cache
.as(not null)
428 redef fun substrings
do return new FlatSubstringsIter(self)
431 private class FlatStringCharReverseIterator
432 super IndexedIterator[Char]
434 var target
: FlatString
438 init with_pos
(tgt
: FlatString, pos
: Int)
443 redef fun is_ok
do return curr_pos
>= 0
445 redef fun item
do return target
[curr_pos
]
447 redef fun next
do curr_pos
-= 1
449 redef fun index
do return curr_pos
453 private class FlatStringCharIterator
454 super IndexedIterator[Char]
456 var target
: FlatString
462 init with_pos
(tgt
: FlatString, pos
: Int)
464 init(tgt
, tgt
.length
- 1, pos
)
467 redef fun is_ok
do return curr_pos
<= max
469 redef fun item
do return target
[curr_pos
]
471 redef fun next
do curr_pos
+= 1
473 redef fun index
do return curr_pos
477 private class FlatStringCharView
480 redef type SELFTYPE: FlatString
482 redef fun [](index
) do return target
[index
]
484 redef fun iterator_from
(start
) do return new FlatStringCharIterator.with_pos
(target
, start
)
486 redef fun reverse_iterator_from
(start
) do return new FlatStringCharReverseIterator.with_pos
(target
, start
)
490 private class FlatStringByteReverseIterator
491 super IndexedIterator[Byte]
493 var target
: FlatString
495 var target_items
: NativeString
499 init with_pos
(tgt
: FlatString, pos
: Int)
501 init(tgt
, tgt
._items
, pos
+ tgt
._first_byte
)
504 redef fun is_ok
do return curr_pos
>= target
._first_byte
506 redef fun item
do return target_items
[curr_pos
]
508 redef fun next
do curr_pos
-= 1
510 redef fun index
do return curr_pos
- target
._first_byte
514 private class FlatStringByteIterator
515 super IndexedIterator[Byte]
517 var target
: FlatString
519 var target_items
: NativeString
523 init with_pos
(tgt
: FlatString, pos
: Int)
525 init(tgt
, tgt
._items
, pos
+ tgt
._first_byte
)
528 redef fun is_ok
do return curr_pos
<= target
._last_byte
530 redef fun item
do return target_items
[curr_pos
]
532 redef fun next
do curr_pos
+= 1
534 redef fun index
do return curr_pos
- target
._first_byte
538 private class FlatStringByteView
541 redef type SELFTYPE: FlatString
545 # Check that the index (+ _first_byte) is not larger than _last_byte
546 # In other terms, if the index is valid
548 var target
= self.target
549 var ind
= index
+ target
._first_byte
550 assert ind
<= target
._last_byte
551 return target
._items
[ind
]
554 redef fun iterator_from
(start
) do return new FlatStringByteIterator.with_pos
(target
, start
)
556 redef fun reverse_iterator_from
(start
) do return new FlatStringByteReverseIterator.with_pos
(target
, start
)
561 redef new do return new FlatBuffer
563 redef new with_cap
(i
) do return new FlatBuffer.with_capacity
(i
)
566 # Mutable strings of characters.
571 redef var chars
: Sequence[Char] = new FlatBufferCharView(self) is lazy
573 redef var bytes
= new FlatBufferByteView(self) is lazy
577 private var char_cache
: Int = -1
579 private var byte_cache
: Int = -1
581 private var capacity
= 0
583 # Real items, used as cache for when to_cstring is called
584 private var real_items
: NativeString is noinit
586 redef fun fast_cstring
do return _items
.fast_cstring
(0)
588 redef fun substrings
do return new FlatSubstringsIter(self)
590 # Re-copies the `NativeString` into a new one and sets it as the new `Buffer`
592 # This happens when an operation modifies the current `Buffer` and
593 # the Copy-On-Write flag `written` is set at true.
595 var nns
= new NativeString(capacity
)
596 if _bytelen
!= 0 then _items
.copy_to
(nns
, _bytelen
, 0, 0)
601 # Shifts the content of the buffer by `len` bytes to the right, starting at byte `from`
603 # Internal only, does not modify _bytelen or length, this is the caller's responsability
604 private fun rshift_bytes
(from
: Int, len
: Int) do
608 if bt
+ len
> capacity
then
609 capacity
= capacity
* 2 + 2
610 nit
= new NativeString(capacity
)
611 oit
.copy_to
(nit
, 0, 0, from
)
613 oit
.copy_to
(nit
, bt
- from
, from
, from
+ len
)
616 # Shifts the content of the buffer by `len` bytes to the left, starting at `from`
618 # Internal only, does not modify _bytelen or length, this is the caller's responsability
619 private fun lshift_bytes
(from
: Int, len
: Int) do
621 it
.copy_to
(it
, _bytelen
- from
, from
, from
- len
)
624 redef fun []=(index
, item
)
626 assert index
>= 0 and index
<= length
627 if written
then reset
629 if index
== length
then
634 var ip
= it
.char_to_byte_index
(index
)
635 var c
= it
.char_at
(ip
)
636 var clen
= c
.u8char_len
637 var itemlen
= item
.u8char_len
638 var size_diff
= itemlen
- clen
639 if size_diff
> 0 then
640 rshift_bytes
(ip
+ clen
, size_diff
)
641 else if size_diff
< 0 then
642 lshift_bytes
(ip
+ clen
, -size_diff
)
644 _bytelen
+= size_diff
646 it
.set_char_at
(ip
, item
)
651 if written
then reset
653 var clen
= c
.u8char_len
656 _items
.set_char_at
(bt
, c
)
663 if written
then reset
668 redef fun empty
do return new Buffer
670 redef fun enlarge
(cap
)
673 if cap
<= c
then return
674 while c
<= cap
do c
= c
* 2 + 2
675 # The COW flag can be set at false here, since
676 # it does a copy of the current `Buffer`
679 var a
= new NativeString(c
+1)
682 if bln
> 0 then it
.copy_to
(a
, bln
, 0, 0)
692 if bln
== 0 then _items
= new NativeString(1)
693 return new FlatString.full
(_items
, bln
, 0, bln
- 1, length
)
700 var new_native
= new NativeString(bln
+ 1)
701 new_native
[bln
] = 0u8
702 if length
> 0 then _items
.copy_to
(new_native
, bln
, 0, 0)
703 real_items
= new_native
709 # Create a new empty string.
712 # Low-level creation a new buffer with given data.
714 # `_items` will be used as is, without copy, to store the characters of the buffer.
715 # Aliasing issues is the responsibility of the caller.
717 # If `_items` is shared, `written` should be set to true after the creation
718 # so that a modification will do a copy-on-write.
719 private init with_infos
(items
: NativeString, capacity
, bytelen
, length
: Int)
722 self.capacity
= capacity
723 self._bytelen
= bytelen
727 # Create a new string copied from `s`.
730 _items
= new NativeString(s
.bytelen
)
731 if s
isa FlatText then
734 for i
in substrings
do i
.as(FlatString)._items
.copy_to
(_items
, i
._bytelen
, 0, 0)
742 # Create a new empty string with a given capacity.
743 init with_capacity
(cap
: Int)
746 _items
= new NativeString(cap
+ 1)
753 if s
.is_empty
then return
756 var nln
= _bytelen
+ sl
758 if s
isa FlatText then
759 s
._items
.copy_to
(_items
, sl
, s
.first_byte
, _bytelen
)
761 for i
in s
.substrings
do append i
768 # Copies the content of self in `dest`
769 fun copy
(start
: Int, len
: Int, dest
: Buffer, new_start
: Int)
771 var self_chars
= self.chars
772 var dest_chars
= dest
.chars
773 for i
in [0..len-1
] do
774 dest_chars
[new_start
+i
] = self_chars
[start
+i
]
778 redef fun substring
(from
, count
)
781 if from
< 0 then from
= 0
782 if (from
+ count
) > length
then count
= length
- from
785 var bytefrom
= its
.char_to_byte_index
(from
)
786 var byteto
= its
.char_to_byte_index
(count
+ from
- 1)
787 byteto
+= its
.char_at
(byteto
).u8char_len
- 1
788 var byte_length
= byteto
- bytefrom
+ 1
789 var r_items
= new NativeString(byte_length
)
790 its
.copy_to
(r_items
, byte_length
, bytefrom
, 0)
791 return new FlatBuffer.with_infos
(r_items
, byte_length
, byte_length
, count
)
800 var ns
= new FlatBuffer.with_capacity
(capacity
)
801 for i
in chars
.reverse_iterator
do ns
.add i
805 redef fun times
(repeats
)
808 var x
= new FlatString.full
(_items
, bln
, 0, bln
- 1, length
)
809 for i
in [1 .. repeats
[ do
816 if written
then reset
817 for i
in [0 .. length
[ do self[i
] = self[i
].to_upper
822 if written
then reset
823 for i
in [0 .. length
[ do self[i
] = self[i
].to_lower
827 private class FlatBufferByteReverseIterator
828 super IndexedIterator[Byte]
830 var target
: FlatBuffer
832 var target_items
: NativeString
836 init with_pos
(tgt
: FlatBuffer, pos
: Int)
838 init(tgt
, tgt
._items
, pos
)
841 redef fun index
do return curr_pos
843 redef fun is_ok
do return curr_pos
>= 0
845 redef fun item
do return target_items
[curr_pos
]
847 redef fun next
do curr_pos
-= 1
851 private class FlatBufferByteView
854 redef type SELFTYPE: FlatBuffer
856 redef fun [](index
) do return target
._items
[index
]
858 redef fun iterator_from
(pos
) do return new FlatBufferByteIterator.with_pos
(target
, pos
)
860 redef fun reverse_iterator_from
(pos
) do return new FlatBufferByteReverseIterator.with_pos
(target
, pos
)
864 private class FlatBufferByteIterator
865 super IndexedIterator[Byte]
867 var target
: FlatBuffer
869 var target_items
: NativeString
873 init with_pos
(tgt
: FlatBuffer, pos
: Int)
875 init(tgt
, tgt
._items
, pos
)
878 redef fun index
do return curr_pos
880 redef fun is_ok
do return curr_pos
< target
._bytelen
882 redef fun item
do return target_items
[curr_pos
]
884 redef fun next
do curr_pos
+= 1
888 private class FlatBufferCharReverseIterator
889 super IndexedIterator[Char]
891 var target
: FlatBuffer
895 init with_pos
(tgt
: FlatBuffer, pos
: Int)
900 redef fun index
do return curr_pos
902 redef fun is_ok
do return curr_pos
>= 0
904 redef fun item
do return target
[curr_pos
]
906 redef fun next
do curr_pos
-= 1
910 private class FlatBufferCharView
913 redef type SELFTYPE: FlatBuffer
915 redef fun [](index
) do return target
[index
]
917 redef fun []=(index
, item
)
919 assert index
>= 0 and index
<= length
920 if index
== length
then
937 fun enlarge
(cap
: Int)
944 var s_length
= s
.length
945 if target
.capacity
< s
.length
then enlarge
(s_length
+ target
.length
)
946 for i
in s
do target
.add i
949 redef fun iterator_from
(pos
) do return new FlatBufferCharIterator.with_pos
(target
, pos
)
951 redef fun reverse_iterator_from
(pos
) do return new FlatBufferCharReverseIterator.with_pos
(target
, pos
)
955 private class FlatBufferCharIterator
956 super IndexedIterator[Char]
958 var target
: FlatBuffer
964 init with_pos
(tgt
: FlatBuffer, pos
: Int)
966 init(tgt
, tgt
.length
- 1, pos
)
969 redef fun index
do return curr_pos
971 redef fun is_ok
do return curr_pos
<= max
973 redef fun item
do return target
[curr_pos
]
975 redef fun next
do curr_pos
+= 1
979 redef class NativeString
982 return to_s_with_length
(cstring_length
)
985 # Returns `self` as a String of `length`.
986 redef fun to_s_with_length
(length
): FlatString
989 return clean_utf8
(length
)
992 redef fun to_s_full
(bytelen
, unilen
) do
993 return new FlatString.full
(self, bytelen
, 0, bytelen
- 1, unilen
)
996 # Returns `self` as a new String.
997 redef fun to_s_with_copy
: FlatString
999 var length
= cstring_length
1000 var r
= clean_utf8
(length
)
1001 if r
.items
!= self then return r
1002 var new_self
= new NativeString(length
+ 1)
1003 copy_to
(new_self
, length
, 0, 0)
1004 var str
= new FlatString.with_infos
(new_self
, length
, 0, length
- 1)
1005 new_self
[length
] = 0u8
1006 str
.to_cstring
= new_self
1010 # Cleans a NativeString if necessary
1011 fun clean_utf8
(len
: Int): FlatString do
1012 var replacements
: nullable Array[Int] = null
1013 var end_length
= len
1018 var nxst
= length_of_char_at
(pos
)
1021 ok_st
= b
& 0x80u
8 == 0u8
1022 else if nxst
== 2 then
1023 ok_st
= b
& 0xE0u
8 == 0xC0u
8
1024 else if nxst
== 3 then
1025 ok_st
= b
& 0xF0u
8 == 0xE0u
8
1027 ok_st
= b
& 0xF8u
8 == 0xF0u
8
1030 if replacements
== null then replacements
= new Array[Int]
1031 replacements
.add pos
1038 var c
= char_at
(pos
)
1039 var cp
= c
.code_point
1041 ok_c
= cp
>= 0 and cp
<= 0x7F
1042 else if nxst
== 2 then
1043 ok_c
= cp
>= 0x80 and cp
<= 0x7FF
1044 else if nxst
== 3 then
1045 ok_c
= cp
>= 0x800 and cp
<= 0xFFFF
1046 ok_c
= ok_c
and not (cp
>= 0xD800 and cp
<= 0xDFFF) and cp
!= 0xFFFE and cp
!= 0xFFFF
1048 ok_c
= cp
>= 0x10000 and cp
<= 0x10FFFF
1051 if replacements
== null then replacements
= new Array[Int]
1052 replacements
.add pos
1062 if end_length
!= len
then
1063 ret
= new NativeString(end_length
)
1066 var repls
= replacements
.as(not null)
1067 var r
= repls
.items
.as(not null)
1068 var imax
= repls
.length
1069 for i
in [0 .. imax
[ do
1071 var chkln
= repl_pos
- old_repl
1072 copy_to
(ret
, chkln
, old_repl
, off
)
1075 ret
[off
+ 1] = 0xBFu
8
1076 ret
[off
+ 2] = 0xBDu
8
1077 old_repl
= repl_pos
+ 1
1080 copy_to
(ret
, len
- old_repl
, old_repl
, off
)
1082 return new FlatString.full
(ret
, end_length
, 0, end_length
- 1, chr_ln
)
1085 # Sets the next bytes at position `pos` to the value of `c`, encoded in UTF-8
1087 # Very unsafe, make sure to have room for this char prior to calling this function.
1088 private fun set_char_at
(pos
: Int, c
: Char) do
1089 var ln
= c
.u8char_len
1090 native_set_char
(pos
, c
, ln
)
1093 private fun native_set_char
(pos
: Int, c
: Char, ln
: Int) `{
1094 char* dst = self + pos;
1100 dst[0] = 0xC0 | ((c & 0x7C0) >> 6);
1101 dst[1] = 0x80 | (c & 0x3F);
1104 dst[0] = 0xE0 | ((c & 0xF000) >> 12);
1105 dst[1] = 0x80 | ((c & 0xFC0) >> 6);
1106 dst[2] = 0x80 | (c & 0x3F);
1109 dst[0] = 0xF0 | ((c & 0x1C0000) >> 18);
1110 dst[1] = 0x80 | ((c & 0x3F000) >> 12);
1111 dst[2] = 0x80 | ((c & 0xFC0) >> 6);
1112 dst[3] = 0x80 | (c & 0x3F);
1119 redef fun to_base
(base
, signed
)
1121 var l
= digit_count
(base
)
1122 var s
= new FlatBuffer.from
(" " * l
)
1123 fill_buffer
(s
, base
, signed
)
1127 # return displayable int in base 10 and signed
1129 # assert 1.to_s == "1"
1130 # assert (-123).to_s == "-123"
1132 # Fast case for common numbers
1133 if self == 0 then return "0"
1134 if self == 1 then return "1"
1136 var nslen
= int_to_s_len
1137 var ns
= new NativeString(nslen
+ 1)
1139 native_int_to_s
(ns
, nslen
+ 1)
1140 return new FlatString.full
(ns
, nslen
, 0, nslen
- 1, nslen
)
1144 redef class Array[E
]
1146 # Fast implementation
1147 redef fun plain_to_s
1150 if l
== 0 then return ""
1151 if l
== 1 then if self[0] == null then return "" else return self[0].to_s
1153 var na
= new NativeArray[String](l
)
1159 if itsi
== null then
1169 var ns
= new NativeString(sl
+ 1)
1175 if tmp
isa FlatString then
1176 var tpl
= tmp
._bytelen
1177 tmp
._items
.copy_to
(ns
, tpl
, tmp
._first_byte
, off
)
1180 for j
in tmp
.substrings
do
1181 var s
= j
.as(FlatString)
1182 var slen
= s
._bytelen
1183 s
._items
.copy_to
(ns
, slen
, s
._first_byte
, off
)
1189 return new FlatString.with_infos
(ns
, sl
, 0, sl
- 1)
1193 redef class NativeArray[E
]
1194 redef fun native_to_s
do
1195 assert self isa NativeArray[String]
1206 var ns
= new NativeString(sl
+ 1)
1212 if tmp
isa FlatString then
1213 var tpl
= tmp
._bytelen
1214 tmp
._items
.copy_to
(ns
, tpl
, tmp
._first_byte
, off
)
1217 for j
in tmp
.substrings
do
1218 var s
= j
.as(FlatString)
1219 var slen
= s
._bytelen
1220 s
._items
.copy_to
(ns
, slen
, s
._first_byte
, off
)
1226 return new FlatString.with_infos
(ns
, sl
, 0, sl
- 1)
1230 redef class Map[K
,V
]
1231 redef fun join
(sep
, couple_sep
)
1233 if is_empty
then return ""
1235 var s
= new Buffer # Result
1241 s
.append
("{k or else "<null>"}{couple_sep}{e or else "<null>"}")
1243 # Concat other _items
1249 s
.append
("{k or else "<null>"}{couple_sep}{e or else "<null>"}")