@@ -565,28 +565,18 @@ isascii(c::Char) = bswap(reinterpret(UInt32, c)) < 0x80
565
565
isascii (s:: AbstractString ) = all (isascii, s)
566
566
isascii (c:: AbstractChar ) = UInt32 (c) < 0x80
567
567
568
- # # string map, filter, has ##
569
- function map (f, s:: AbstractString )
570
- out = IOBuffer (sizehint= sizeof (s))
571
- for c in s
572
- c′ = f (c)
573
- isa (c′, AbstractChar) || throw (ArgumentError (
574
- " map(f, s::AbstractString) requires f to return AbstractChar; try map(f, collect(s)) or a comprehension instead" ))
575
- write (out, c′:: AbstractChar )
576
- end
577
- String (take! (out))
578
- end
568
+ # # string map, filter ##
579
569
580
- function map (f, s:: String )
570
+ function map (f, s:: AbstractString )
581
571
out = StringVector (max (4 , sizeof (s)÷ sizeof (codeunit (s))))
582
572
index = UInt (1 )
583
573
for c in s
584
574
c′ = f (c)
585
- isa (c′, Char ) || throw (ArgumentError (
586
- " map(f, s::String ) requires f to return Char ; " *
575
+ isa (c′, AbstractChar ) || throw (ArgumentError (
576
+ " map(f, s::AbstractString ) requires f to return AbstractChar ; " *
587
577
" try map(f, collect(s)) or a comprehension instead" ))
588
578
index + 3 > length (out) && resize! (out, unsigned (2 * length (out)))
589
- index += __unsafe_string! (out, c′ , index)
579
+ index += __unsafe_string! (out, convert (Char, c′) , index)
590
580
end
591
581
resize! (out, index- 1 )
592
582
sizehint! (out, index- 1 )
0 commit comments