Skip to content

Commit 76d8096

Browse files
committed
Merge remote-tracking branch 'origin/length'
2 parents 570444d + 9aa11e1 commit 76d8096

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

System/OsString/Common.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,20 @@ null = coerce BSP.null
502502

503503
-- | /O(1)/ The length of a 'OsString'.
504504
--
505+
-- This returns the number of code units
506+
-- (@Word8@ on unix and @Word16@ on windows), not
507+
-- bytes.
508+
--
509+
-- >>> length "abc"
510+
-- 3
511+
--
505512
-- @since 1.4.200.0
506513
length :: PLATFORM_STRING -> Int
514+
#ifdef WINDOWS
515+
length = coerce BSP.numWord16
516+
#else
507517
length = coerce BSP.length
518+
#endif
508519

509520
-- | /O(n)/ 'map' @f xs@ is the OsString obtained by applying @f@ to each
510521
-- element of @xs@.

tests/bytestring-tests/Properties/Common.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ tests =
454454

455455
, ("length" ,
456456
property $ \x -> numWord x === fromIntegral (length (B.unpack x)))
457+
#if defined(OSWORD) || defined(WIN) || defined(POSIX)
458+
, ("length abc" ,
459+
once $ B.length (B.pack [0xbb, 0x03]) == 2)
460+
#endif
457461
, ("count" ,
458462
property $ \(toElem -> c) x -> B.count c x === fromIntegral (length (elemIndices c (B.unpack x))))
459463
, ("filter" ,

0 commit comments

Comments
 (0)