From 79981caa15e817f84f8b5a22198ac133b408ba40 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sun, 7 Jun 2020 15:19:49 +0100 Subject: [PATCH 01/26] Bump pulp version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 28a3fd3..e868f88 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "eslint": "^4.19.1", - "pulp": "^12.2.0", + "pulp": "^15.0.0", "purescript-psa": "^0.6.0", "rimraf": "^2.6.2" } From cc98047aea84eb2ea18969998cc611e176d8d671 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Sun, 15 Nov 2020 07:02:28 -0800 Subject: [PATCH 02/26] Update to v0.14.0-rc3 (#129) * Update TAG to v0.14.0-rc3; dependencies to master; psa to v0.8.0 * Account for `fromRight` breaking change --- .travis.yml | 3 ++- bower.json | 38 +++++++++++++++---------------- package.json | 2 +- src/Data/String/Regex/Unsafe.purs | 7 +++--- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8daa38c..116705f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ node_js: stable env: - PATH=$HOME/purescript:$PATH install: - - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest)) + # - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest)) + - TAG=v0.14.0-rc3 - curl --location --output $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz - tar -xvf $HOME/purescript.tar.gz -C $HOME/ - chmod a+x $HOME/purescript diff --git a/bower.json b/bower.json index ec7fb7f..e401464 100644 --- a/bower.json +++ b/bower.json @@ -16,26 +16,26 @@ "package.json" ], "dependencies": { - "purescript-arrays": "^5.0.0", - "purescript-control": "^4.0.0", - "purescript-either": "^4.0.0", - "purescript-enums": "^4.0.0", - "purescript-foldable-traversable": "^4.0.0", - "purescript-gen": "^2.0.0", - "purescript-integers": "^4.0.0", - "purescript-maybe": "^4.0.0", - "purescript-newtype": "^3.0.0", - "purescript-nonempty": "^5.0.0", - "purescript-partial": "^2.0.0", - "purescript-prelude": "^4.0.0", - "purescript-tailrec": "^4.0.0", - "purescript-tuples": "^5.0.0", - "purescript-unfoldable": "^4.0.0", - "purescript-unsafe-coerce": "^4.0.0" + "purescript-arrays": "master", + "purescript-control": "master", + "purescript-either": "master", + "purescript-enums": "master", + "purescript-foldable-traversable": "master", + "purescript-gen": "master", + "purescript-integers": "master", + "purescript-maybe": "master", + "purescript-newtype": "master", + "purescript-nonempty": "master", + "purescript-partial": "master", + "purescript-prelude": "master", + "purescript-tailrec": "master", + "purescript-tuples": "master", + "purescript-unfoldable": "master", + "purescript-unsafe-coerce": "master" }, "devDependencies": { - "purescript-assert": "^4.0.0", - "purescript-console": "^4.0.0", - "purescript-minibench": "^2.0.0" + "purescript-assert": "master", + "purescript-console": "master", + "purescript-minibench": "master" } } diff --git a/package.json b/package.json index e868f88..1f09388 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "devDependencies": { "eslint": "^4.19.1", "pulp": "^15.0.0", - "purescript-psa": "^0.6.0", + "purescript-psa": "^0.8.0", "rimraf": "^2.6.2" } } diff --git a/src/Data/String/Regex/Unsafe.purs b/src/Data/String/Regex/Unsafe.purs index 0a982c6..3cbd0ae 100644 --- a/src/Data/String/Regex/Unsafe.purs +++ b/src/Data/String/Regex/Unsafe.purs @@ -2,13 +2,14 @@ module Data.String.Regex.Unsafe ( unsafeRegex ) where -import Data.Either (fromRight) +import Control.Category (identity) +import Data.Either (either) import Data.String.Regex (Regex, regex) import Data.String.Regex.Flags (RegexFlags) -import Partial.Unsafe (unsafePartial) +import Partial.Unsafe (unsafeCrashWith) -- | Constructs a `Regex` from a pattern string and flags. Fails with -- | an exception if the pattern contains a syntax error. unsafeRegex :: String -> RegexFlags -> Regex -unsafeRegex s f = unsafePartial fromRight (regex s f) +unsafeRegex s f = either unsafeCrashWith identity (regex s f) From 176633dc6d540b7ec279d970ead65b2ce2c734aa Mon Sep 17 00:00:00 2001 From: toastal Date: Thu, 19 Nov 2020 23:47:22 +0000 Subject: [PATCH 03/26] Fix line endings and formatting to match project (#132) --- src/Data/String/Regex/Unsafe.purs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Data/String/Regex/Unsafe.purs b/src/Data/String/Regex/Unsafe.purs index 3cbd0ae..8afd1a2 100644 --- a/src/Data/String/Regex/Unsafe.purs +++ b/src/Data/String/Regex/Unsafe.purs @@ -1,15 +1,14 @@ -module Data.String.Regex.Unsafe -( unsafeRegex -) where - -import Control.Category (identity) -import Data.Either (either) -import Data.String.Regex (Regex, regex) -import Data.String.Regex.Flags (RegexFlags) - -import Partial.Unsafe (unsafeCrashWith) - --- | Constructs a `Regex` from a pattern string and flags. Fails with --- | an exception if the pattern contains a syntax error. -unsafeRegex :: String -> RegexFlags -> Regex -unsafeRegex s f = either unsafeCrashWith identity (regex s f) +module Data.String.Regex.Unsafe + ( unsafeRegex + ) where + +import Control.Category (identity) +import Data.Either (either) +import Data.String.Regex (Regex, regex) +import Data.String.Regex.Flags (RegexFlags) +import Partial.Unsafe (unsafeCrashWith) + +-- | Constructs a `Regex` from a pattern string and flags. Fails with +-- | an exception if the pattern contains a syntax error. +unsafeRegex :: String -> RegexFlags -> Regex +unsafeRegex s f = either unsafeCrashWith identity (regex s f) From 848b3309e4325a30cf60e295e4a266806df9a777 Mon Sep 17 00:00:00 2001 From: Cyril Sobierajewicz Date: Mon, 23 Nov 2020 21:06:28 +0100 Subject: [PATCH 04/26] Replace monomorphic proxies by Type.Proxy.Proxy and polymorphic variables --- src/Data/String/NonEmpty/Internal.purs | 6 +- test/Test/Data/String/NonEmpty.purs | 138 +++++------ test/Test/Data/String/NonEmpty/CodeUnits.purs | 234 +++++++++--------- 3 files changed, 189 insertions(+), 189 deletions(-) diff --git a/src/Data/String/NonEmpty/Internal.purs b/src/Data/String/NonEmpty/Internal.purs index bfd2984..7a6197e 100644 --- a/src/Data/String/NonEmpty/Internal.purs +++ b/src/Data/String/NonEmpty/Internal.purs @@ -8,7 +8,7 @@ import Data.Maybe (Maybe(..), fromJust) import Data.Semigroup.Foldable (class Foldable1) import Data.String as String import Data.String.Pattern (Pattern) -import Data.Symbol (class IsSymbol, SProxy, reflectSymbol) +import Data.Symbol (class IsSymbol, reflectSymbol) import Prim.TypeError as TE import Unsafe.Coerce (unsafeCoerce) @@ -26,10 +26,10 @@ instance showNonEmptyString :: Show NonEmptyString where -- | -- | ``` purescript -- | something :: NonEmptyString --- | something = nes (SProxy :: SProxy "something") +-- | something = nes (Proxy :: Proxy "something") -- | ``` class MakeNonEmpty (s :: Symbol) where - nes :: SProxy s -> NonEmptyString + nes :: forall proxy. proxy s -> NonEmptyString instance makeNonEmptyBad :: TE.Fail (TE.Text "Cannot create an NonEmptyString from an empty Symbol") => MakeNonEmpty "" where nes _ = NonEmptyString "" diff --git a/test/Test/Data/String/NonEmpty.purs b/test/Test/Data/String/NonEmpty.purs index 59a8f22..a4103ec 100644 --- a/test/Test/Data/String/NonEmpty.purs +++ b/test/Test/Data/String/NonEmpty.purs @@ -6,11 +6,11 @@ import Data.Array.NonEmpty as NEA import Data.Maybe (Maybe(..), fromJust) import Data.String.NonEmpty (Pattern(..), nes) import Data.String.NonEmpty as NES -import Data.Symbol (SProxy(..)) import Effect (Effect) import Effect.Console (log) import Partial.Unsafe (unsafePartial) import Test.Assert (assert, assertEqual) +import Type.Proxy (Proxy(..)) testNonEmptyString :: Effect Unit testNonEmptyString = do @@ -22,7 +22,7 @@ testNonEmptyString = do } assertEqual { actual: NES.fromString "hello" - , expected: Just (nes (SProxy :: SProxy "hello")) + , expected: Just (nes (Proxy :: Proxy "hello")) } log "toString" @@ -33,136 +33,136 @@ testNonEmptyString = do log "appendString" assertEqual - { actual: NES.appendString (nes (SProxy :: SProxy "Hello")) " world" - , expected: nes (SProxy :: SProxy "Hello world") + { actual: NES.appendString (nes (Proxy :: Proxy "Hello")) " world" + , expected: nes (Proxy :: Proxy "Hello world") } assertEqual - { actual: NES.appendString (nes (SProxy :: SProxy "Hello")) "" - , expected: nes (SProxy :: SProxy "Hello") + { actual: NES.appendString (nes (Proxy :: Proxy "Hello")) "" + , expected: nes (Proxy :: Proxy "Hello") } log "prependString" assertEqual - { actual: NES.prependString "be" (nes (SProxy :: SProxy "fore")) - , expected: nes (SProxy :: SProxy "before") + { actual: NES.prependString "be" (nes (Proxy :: Proxy "fore")) + , expected: nes (Proxy :: Proxy "before") } assertEqual - { actual: NES.prependString "" (nes (SProxy :: SProxy "fore")) - , expected: nes (SProxy :: SProxy "fore") + { actual: NES.prependString "" (nes (Proxy :: Proxy "fore")) + , expected: nes (Proxy :: Proxy "fore") } log "contains" - assert $ NES.contains (Pattern "") (nes (SProxy :: SProxy "abcd")) - assert $ NES.contains (Pattern "bc") (nes (SProxy :: SProxy "abcd")) - assert $ not NES.contains (Pattern "cb") (nes (SProxy :: SProxy "abcd")) - assert $ NES.contains (Pattern "needle") (nes (SProxy :: SProxy "haystack with needle")) - assert $ not NES.contains (Pattern "needle") (nes (SProxy :: SProxy "haystack")) + assert $ NES.contains (Pattern "") (nes (Proxy :: Proxy "abcd")) + assert $ NES.contains (Pattern "bc") (nes (Proxy :: Proxy "abcd")) + assert $ not NES.contains (Pattern "cb") (nes (Proxy :: Proxy "abcd")) + assert $ NES.contains (Pattern "needle") (nes (Proxy :: Proxy "haystack with needle")) + assert $ not NES.contains (Pattern "needle") (nes (Proxy :: Proxy "haystack")) log "localeCompare" assertEqual - { actual: NES.localeCompare (nes (SProxy :: SProxy "a")) (nes (SProxy :: SProxy "a")) + { actual: NES.localeCompare (nes (Proxy :: Proxy "a")) (nes (Proxy :: Proxy "a")) , expected: EQ } assertEqual - { actual: NES.localeCompare (nes (SProxy :: SProxy "a")) (nes (SProxy :: SProxy "b")) + { actual: NES.localeCompare (nes (Proxy :: Proxy "a")) (nes (Proxy :: Proxy "b")) , expected: LT } assertEqual - { actual: NES.localeCompare (nes (SProxy :: SProxy "b")) (nes (SProxy :: SProxy "a")) + { actual: NES.localeCompare (nes (Proxy :: Proxy "b")) (nes (Proxy :: Proxy "a")) , expected: GT } log "replace" assertEqual - { actual: NES.replace (Pattern "b") (NES.NonEmptyReplacement (nes (SProxy :: SProxy "!"))) (nes (SProxy :: SProxy "abc")) - , expected: nes (SProxy :: SProxy "a!c") + { actual: NES.replace (Pattern "b") (NES.NonEmptyReplacement (nes (Proxy :: Proxy "!"))) (nes (Proxy :: Proxy "abc")) + , expected: nes (Proxy :: Proxy "a!c") } assertEqual - { actual: NES.replace (Pattern "b") (NES.NonEmptyReplacement (nes (SProxy :: SProxy "!"))) (nes (SProxy :: SProxy "abbc")) - , expected: nes (SProxy :: SProxy "a!bc") + { actual: NES.replace (Pattern "b") (NES.NonEmptyReplacement (nes (Proxy :: Proxy "!"))) (nes (Proxy :: Proxy "abbc")) + , expected: nes (Proxy :: Proxy "a!bc") } assertEqual - { actual: NES.replace (Pattern "d") (NES.NonEmptyReplacement (nes (SProxy :: SProxy "!"))) (nes (SProxy :: SProxy "abc")) - , expected: nes (SProxy :: SProxy "abc") + { actual: NES.replace (Pattern "d") (NES.NonEmptyReplacement (nes (Proxy :: Proxy "!"))) (nes (Proxy :: Proxy "abc")) + , expected: nes (Proxy :: Proxy "abc") } log "replaceAll" assertEqual - { actual: NES.replaceAll (Pattern "[b]") (NES.NonEmptyReplacement (nes (SProxy :: SProxy "!"))) (nes (SProxy :: SProxy "a[b]c")) - , expected: nes (SProxy :: SProxy "a!c") + { actual: NES.replaceAll (Pattern "[b]") (NES.NonEmptyReplacement (nes (Proxy :: Proxy "!"))) (nes (Proxy :: Proxy "a[b]c")) + , expected: nes (Proxy :: Proxy "a!c") } assertEqual - { actual: NES.replaceAll (Pattern "[b]") (NES.NonEmptyReplacement (nes (SProxy :: SProxy "!"))) (nes (SProxy :: SProxy "a[b]c[b]")) - , expected: nes (SProxy :: SProxy "a!c!") + { actual: NES.replaceAll (Pattern "[b]") (NES.NonEmptyReplacement (nes (Proxy :: Proxy "!"))) (nes (Proxy :: Proxy "a[b]c[b]")) + , expected: nes (Proxy :: Proxy "a!c!") } assertEqual - { actual: NES.replaceAll (Pattern "x") (NES.NonEmptyReplacement (nes (SProxy :: SProxy "!"))) (nes (SProxy :: SProxy "abc")) - , expected: nes (SProxy :: SProxy "abc") + { actual: NES.replaceAll (Pattern "x") (NES.NonEmptyReplacement (nes (Proxy :: Proxy "!"))) (nes (Proxy :: Proxy "abc")) + , expected: nes (Proxy :: Proxy "abc") } log "stripPrefix" assertEqual - { actual: NES.stripPrefix (Pattern "") (nes (SProxy :: SProxy "abc")) - , expected: Just (nes (SProxy :: SProxy "abc")) + { actual: NES.stripPrefix (Pattern "") (nes (Proxy :: Proxy "abc")) + , expected: Just (nes (Proxy :: Proxy "abc")) } assertEqual - { actual: NES.stripPrefix (Pattern "a") (nes (SProxy :: SProxy "abc")) - , expected: Just (nes (SProxy :: SProxy "bc")) + { actual: NES.stripPrefix (Pattern "a") (nes (Proxy :: Proxy "abc")) + , expected: Just (nes (Proxy :: Proxy "bc")) } assertEqual - { actual: NES.stripPrefix (Pattern "abc") (nes (SProxy :: SProxy "abc")) + { actual: NES.stripPrefix (Pattern "abc") (nes (Proxy :: Proxy "abc")) , expected: Nothing } assertEqual - { actual: NES.stripPrefix (Pattern "!") (nes (SProxy :: SProxy "abc")) + { actual: NES.stripPrefix (Pattern "!") (nes (Proxy :: Proxy "abc")) , expected: Nothing } assertEqual - { actual: NES.stripPrefix (Pattern "http:") (nes (SProxy :: SProxy "http://purescript.org")) - , expected: Just (nes (SProxy :: SProxy "//purescript.org")) + { actual: NES.stripPrefix (Pattern "http:") (nes (Proxy :: Proxy "http://purescript.org")) + , expected: Just (nes (Proxy :: Proxy "//purescript.org")) } assertEqual - { actual: NES.stripPrefix (Pattern "http:") (nes (SProxy :: SProxy "https://purescript.org")) + { actual: NES.stripPrefix (Pattern "http:") (nes (Proxy :: Proxy "https://purescript.org")) , expected: Nothing } assertEqual - { actual: NES.stripPrefix (Pattern "Hello!") (nes (SProxy :: SProxy "Hello!")) + { actual: NES.stripPrefix (Pattern "Hello!") (nes (Proxy :: Proxy "Hello!")) , expected: Nothing } log "stripSuffix" assertEqual - { actual: NES.stripSuffix (Pattern ".exe") (nes (SProxy :: SProxy "purs.exe")) - , expected: Just (nes (SProxy :: SProxy "purs")) + { actual: NES.stripSuffix (Pattern ".exe") (nes (Proxy :: Proxy "purs.exe")) + , expected: Just (nes (Proxy :: Proxy "purs")) } assertEqual - { actual: NES.stripSuffix (Pattern ".exe") (nes (SProxy :: SProxy "purs")) + { actual: NES.stripSuffix (Pattern ".exe") (nes (Proxy :: Proxy "purs")) , expected: Nothing } assertEqual - { actual: NES.stripSuffix (Pattern "Hello!") (nes (SProxy :: SProxy "Hello!")) + { actual: NES.stripSuffix (Pattern "Hello!") (nes (Proxy :: Proxy "Hello!")) , expected: Nothing } log "toLower" assertEqual - { actual: NES.toLower (nes (SProxy :: SProxy "bAtMaN")) - , expected: nes (SProxy :: SProxy "batman") + { actual: NES.toLower (nes (Proxy :: Proxy "bAtMaN")) + , expected: nes (Proxy :: Proxy "batman") } log "toUpper" assertEqual - { actual: NES.toUpper (nes (SProxy :: SProxy "bAtMaN")) - , expected: nes (SProxy :: SProxy "BATMAN") + { actual: NES.toUpper (nes (Proxy :: Proxy "bAtMaN")) + , expected: nes (Proxy :: Proxy "BATMAN") } log "trim" assertEqual - { actual: NES.trim (nes (SProxy :: SProxy " abc ")) - , expected: Just (nes (SProxy :: SProxy "abc")) + { actual: NES.trim (nes (Proxy :: Proxy " abc ")) + , expected: Just (nes (Proxy :: Proxy "abc")) } assertEqual - { actual: NES.trim (nes (SProxy :: SProxy " \n")) + { actual: NES.trim (nes (Proxy :: Proxy " \n")) , expected: Nothing } @@ -172,48 +172,48 @@ testNonEmptyString = do , expected: "" } assertEqual - { actual: NES.joinWith "" [nes (SProxy :: SProxy "a"), nes (SProxy :: SProxy "b")] + { actual: NES.joinWith "" [nes (Proxy :: Proxy "a"), nes (Proxy :: Proxy "b")] , expected: "ab" } assertEqual - { actual: NES.joinWith "--" [nes (SProxy :: SProxy "a"), nes (SProxy :: SProxy "b"), nes (SProxy :: SProxy "c")] + { actual: NES.joinWith "--" [nes (Proxy :: Proxy "a"), nes (Proxy :: Proxy "b"), nes (Proxy :: Proxy "c")] , expected: "a--b--c" } log "join1With" assertEqual - { actual: NES.join1With "" (nea [nes (SProxy :: SProxy "a"), nes (SProxy :: SProxy "b")]) - , expected: nes (SProxy :: SProxy "ab") + { actual: NES.join1With "" (nea [nes (Proxy :: Proxy "a"), nes (Proxy :: Proxy "b")]) + , expected: nes (Proxy :: Proxy "ab") } assertEqual - { actual: NES.join1With "--" (nea [nes (SProxy :: SProxy "a"), nes (SProxy :: SProxy "b"), nes (SProxy :: SProxy "c")]) - , expected: nes (SProxy :: SProxy "a--b--c") + { actual: NES.join1With "--" (nea [nes (Proxy :: Proxy "a"), nes (Proxy :: Proxy "b"), nes (Proxy :: Proxy "c")]) + , expected: nes (Proxy :: Proxy "a--b--c") } assertEqual - { actual: NES.join1With ", " (nea [nes (SProxy :: SProxy "apple"), nes (SProxy :: SProxy "banana")]) - , expected: nes (SProxy :: SProxy "apple, banana") + { actual: NES.join1With ", " (nea [nes (Proxy :: Proxy "apple"), nes (Proxy :: Proxy "banana")]) + , expected: nes (Proxy :: Proxy "apple, banana") } assertEqual - { actual: NES.join1With "" (nea [nes (SProxy :: SProxy "apple"), nes (SProxy :: SProxy "banana")]) - , expected: nes (SProxy :: SProxy "applebanana") + { actual: NES.join1With "" (nea [nes (Proxy :: Proxy "apple"), nes (Proxy :: Proxy "banana")]) + , expected: nes (Proxy :: Proxy "applebanana") } log "joinWith1" assertEqual - { actual: NES.joinWith1 (nes (SProxy :: SProxy " ")) (nea ["a", "b"]) - , expected: nes (SProxy :: SProxy "a b") + { actual: NES.joinWith1 (nes (Proxy :: Proxy " ")) (nea ["a", "b"]) + , expected: nes (Proxy :: Proxy "a b") } assertEqual - { actual: NES.joinWith1 (nes (SProxy :: SProxy "--")) (nea ["a", "b", "c"]) - , expected: nes (SProxy :: SProxy "a--b--c") + { actual: NES.joinWith1 (nes (Proxy :: Proxy "--")) (nea ["a", "b", "c"]) + , expected: nes (Proxy :: Proxy "a--b--c") } assertEqual - { actual: NES.joinWith1 (nes (SProxy :: SProxy ", ")) (nea ["apple", "banana"]) - , expected: nes (SProxy :: SProxy "apple, banana") + { actual: NES.joinWith1 (nes (Proxy :: Proxy ", ")) (nea ["apple", "banana"]) + , expected: nes (Proxy :: Proxy "apple, banana") } assertEqual - { actual: NES.joinWith1 (nes (SProxy :: SProxy "/")) (nea ["a", "b", "", "c", ""]) - , expected: nes (SProxy :: SProxy "a/b//c/") + { actual: NES.joinWith1 (nes (Proxy :: Proxy "/")) (nea ["a", "b", "", "c", ""]) + , expected: nes (Proxy :: Proxy "a/b//c/") } nea :: Array ~> NEA.NonEmptyArray diff --git a/test/Test/Data/String/NonEmpty/CodeUnits.purs b/test/Test/Data/String/NonEmpty/CodeUnits.purs index fee9b51..0e78ee8 100644 --- a/test/Test/Data/String/NonEmpty/CodeUnits.purs +++ b/test/Test/Data/String/NonEmpty/CodeUnits.purs @@ -7,11 +7,11 @@ import Data.Enum (fromEnum) import Data.Maybe (Maybe(..), fromJust) import Data.String.NonEmpty (Pattern(..), nes) import Data.String.NonEmpty.CodeUnits as NESCU -import Data.Symbol (SProxy(..)) import Effect (Effect) import Effect.Console (log) import Partial.Unsafe (unsafePartial) import Test.Assert (assertEqual) +import Type.Proxy (Proxy(..)) testNonEmptyStringCodeUnits :: Effect Unit testNonEmptyStringCodeUnits = do @@ -23,7 +23,7 @@ testNonEmptyStringCodeUnits = do } assertEqual { actual: NESCU.fromCharArray ['a', 'b'] - , expected: Just (nes (SProxy :: SProxy "ab")) + , expected: Just (nes (Proxy :: Proxy "ab")) } log "fromNonEmptyCharArray" @@ -35,415 +35,415 @@ testNonEmptyStringCodeUnits = do log "singleton" assertEqual { actual: NESCU.singleton 'a' - , expected: nes (SProxy :: SProxy "a") + , expected: nes (Proxy :: Proxy "a") } log "cons" assertEqual { actual: NESCU.cons 'a' "bc" - , expected: nes (SProxy :: SProxy "abc") + , expected: nes (Proxy :: Proxy "abc") } assertEqual { actual: NESCU.cons 'a' "" - , expected: nes (SProxy :: SProxy "a") + , expected: nes (Proxy :: Proxy "a") } log "snoc" assertEqual { actual: NESCU.snoc 'c' "ab" - , expected: nes (SProxy :: SProxy "abc") + , expected: nes (Proxy :: Proxy "abc") } assertEqual { actual: NESCU.snoc 'a' "" - , expected: nes (SProxy :: SProxy "a") + , expected: nes (Proxy :: Proxy "a") } log "fromFoldable1" assertEqual { actual: NESCU.fromFoldable1 (nea ['a']) - , expected: nes (SProxy :: SProxy "a") + , expected: nes (Proxy :: Proxy "a") } assertEqual { actual: NESCU.fromFoldable1 (nea ['a', 'b', 'c']) - , expected: nes (SProxy :: SProxy "abc") + , expected: nes (Proxy :: Proxy "abc") } log "charAt" assertEqual - { actual: NESCU.charAt 0 (nes (SProxy :: SProxy "a")) + { actual: NESCU.charAt 0 (nes (Proxy :: Proxy "a")) , expected: Just 'a' } assertEqual - { actual: NESCU.charAt 1 (nes (SProxy :: SProxy "a")) + { actual: NESCU.charAt 1 (nes (Proxy :: Proxy "a")) , expected: Nothing } assertEqual - { actual: NESCU.charAt 0 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.charAt 0 (nes (Proxy :: Proxy "ab")) , expected: Just 'a' } assertEqual - { actual: NESCU.charAt 1 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.charAt 1 (nes (Proxy :: Proxy "ab")) , expected: Just 'b' } assertEqual - { actual: NESCU.charAt 2 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.charAt 2 (nes (Proxy :: Proxy "ab")) , expected: Nothing } assertEqual - { actual: NESCU.charAt 2 (nes (SProxy :: SProxy "Hello")) + { actual: NESCU.charAt 2 (nes (Proxy :: Proxy "Hello")) , expected: Just 'l' } assertEqual - { actual: NESCU.charAt 10 (nes (SProxy :: SProxy "Hello")) + { actual: NESCU.charAt 10 (nes (Proxy :: Proxy "Hello")) , expected: Nothing } log "charCodeAt" assertEqual - { actual: fromEnum <$> NESCU.charAt 0 (nes (SProxy :: SProxy "a")) + { actual: fromEnum <$> NESCU.charAt 0 (nes (Proxy :: Proxy "a")) , expected: Just 97 } assertEqual - { actual: fromEnum <$> NESCU.charAt 1 (nes (SProxy :: SProxy "a")) + { actual: fromEnum <$> NESCU.charAt 1 (nes (Proxy :: Proxy "a")) , expected: Nothing } assertEqual - { actual: fromEnum <$> NESCU.charAt 0 (nes (SProxy :: SProxy "ab")) + { actual: fromEnum <$> NESCU.charAt 0 (nes (Proxy :: Proxy "ab")) , expected: Just 97 } assertEqual - { actual: fromEnum <$> NESCU.charAt 1 (nes (SProxy :: SProxy "ab")) + { actual: fromEnum <$> NESCU.charAt 1 (nes (Proxy :: Proxy "ab")) , expected: Just 98 } assertEqual - { actual: fromEnum <$> NESCU.charAt 2 (nes (SProxy :: SProxy "ab")) + { actual: fromEnum <$> NESCU.charAt 2 (nes (Proxy :: Proxy "ab")) , expected: Nothing } assertEqual - { actual: fromEnum <$> NESCU.charAt 2 (nes (SProxy :: SProxy "5 €")) + { actual: fromEnum <$> NESCU.charAt 2 (nes (Proxy :: Proxy "5 €")) , expected: Just 0x20AC } assertEqual - { actual: fromEnum <$> NESCU.charAt 10 (nes (SProxy :: SProxy "5 €")) + { actual: fromEnum <$> NESCU.charAt 10 (nes (Proxy :: Proxy "5 €")) , expected: Nothing } log "toChar" assertEqual - { actual: NESCU.toChar (nes (SProxy :: SProxy "a")) + { actual: NESCU.toChar (nes (Proxy :: Proxy "a")) , expected: Just 'a' } assertEqual - { actual: NESCU.toChar (nes (SProxy :: SProxy "ab")) + { actual: NESCU.toChar (nes (Proxy :: Proxy "ab")) , expected: Nothing } log "toCharArray" assertEqual - { actual: NESCU.toCharArray (nes (SProxy :: SProxy "a")) + { actual: NESCU.toCharArray (nes (Proxy :: Proxy "a")) , expected: ['a'] } assertEqual - { actual: NESCU.toCharArray (nes (SProxy :: SProxy "ab")) + { actual: NESCU.toCharArray (nes (Proxy :: Proxy "ab")) , expected: ['a', 'b'] } assertEqual - { actual: NESCU.toCharArray (nes (SProxy :: SProxy "Hello☺\n")) + { actual: NESCU.toCharArray (nes (Proxy :: Proxy "Hello☺\n")) , expected: ['H','e','l','l','o','☺','\n'] } log "toNonEmptyCharArray" assertEqual - { actual: NESCU.toNonEmptyCharArray (nes (SProxy :: SProxy "ab")) + { actual: NESCU.toNonEmptyCharArray (nes (Proxy :: Proxy "ab")) , expected: nea ['a', 'b'] } log "uncons" assertEqual - { actual: NESCU.uncons (nes (SProxy :: SProxy "a")) + { actual: NESCU.uncons (nes (Proxy :: Proxy "a")) , expected: { head: 'a', tail: Nothing } } assertEqual - { actual: NESCU.uncons (nes (SProxy :: SProxy "Hello World")) - , expected: { head: 'H', tail: Just (nes (SProxy :: SProxy "ello World")) } + { actual: NESCU.uncons (nes (Proxy :: Proxy "Hello World")) + , expected: { head: 'H', tail: Just (nes (Proxy :: Proxy "ello World")) } } log "takeWhile" assertEqual - { actual: NESCU.takeWhile (\c -> true) (nes (SProxy :: SProxy "abc")) - , expected: Just (nes (SProxy :: SProxy "abc")) + { actual: NESCU.takeWhile (\c -> true) (nes (Proxy :: Proxy "abc")) + , expected: Just (nes (Proxy :: Proxy "abc")) } assertEqual - { actual: NESCU.takeWhile (\c -> false) (nes (SProxy :: SProxy "abc")) + { actual: NESCU.takeWhile (\c -> false) (nes (Proxy :: Proxy "abc")) , expected: Nothing } assertEqual - { actual: NESCU.takeWhile (\c -> c /= 'b') (nes (SProxy :: SProxy "aabbcc")) - , expected: Just (nes (SProxy :: SProxy "aa")) + { actual: NESCU.takeWhile (\c -> c /= 'b') (nes (Proxy :: Proxy "aabbcc")) + , expected: Just (nes (Proxy :: Proxy "aa")) } assertEqual - { actual: NESCU.takeWhile (_ /= ':') (nes (SProxy :: SProxy "http://purescript.org")) - , expected: Just (nes (SProxy :: SProxy "http")) + { actual: NESCU.takeWhile (_ /= ':') (nes (Proxy :: Proxy "http://purescript.org")) + , expected: Just (nes (Proxy :: Proxy "http")) } assertEqual - { actual: NESCU.takeWhile (_ == 'a') (nes (SProxy :: SProxy "xyz")) + { actual: NESCU.takeWhile (_ == 'a') (nes (Proxy :: Proxy "xyz")) , expected: Nothing } log "dropWhile" assertEqual - { actual: NESCU.dropWhile (\c -> true) (nes (SProxy :: SProxy "abc")) + { actual: NESCU.dropWhile (\c -> true) (nes (Proxy :: Proxy "abc")) , expected: Nothing } assertEqual - { actual: NESCU.dropWhile (\c -> false) (nes (SProxy :: SProxy "abc")) - , expected: Just (nes (SProxy :: SProxy "abc")) + { actual: NESCU.dropWhile (\c -> false) (nes (Proxy :: Proxy "abc")) + , expected: Just (nes (Proxy :: Proxy "abc")) } assertEqual - { actual: NESCU.dropWhile (\c -> c /= 'b') (nes (SProxy :: SProxy "aabbcc")) - , expected: Just (nes (SProxy :: SProxy "bbcc")) + { actual: NESCU.dropWhile (\c -> c /= 'b') (nes (Proxy :: Proxy "aabbcc")) + , expected: Just (nes (Proxy :: Proxy "bbcc")) } assertEqual - { actual: NESCU.dropWhile (_ /= '.') (nes (SProxy :: SProxy "Test.purs")) - , expected: Just (nes (SProxy :: SProxy ".purs")) + { actual: NESCU.dropWhile (_ /= '.') (nes (Proxy :: Proxy "Test.purs")) + , expected: Just (nes (Proxy :: Proxy ".purs")) } log "indexOf" assertEqual - { actual: NESCU.indexOf (Pattern "") (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.indexOf (Pattern "") (nes (Proxy :: Proxy "abcd")) , expected: Just 0 } assertEqual - { actual: NESCU.indexOf (Pattern "bc") (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.indexOf (Pattern "bc") (nes (Proxy :: Proxy "abcd")) , expected: Just 1 } assertEqual - { actual: NESCU.indexOf (Pattern "cb") (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.indexOf (Pattern "cb") (nes (Proxy :: Proxy "abcd")) , expected: Nothing } log "indexOf'" assertEqual - { actual: NESCU.indexOf' (Pattern "") (-1) (nes (SProxy :: SProxy "ab")) + { actual: NESCU.indexOf' (Pattern "") (-1) (nes (Proxy :: Proxy "ab")) , expected: Nothing } assertEqual - { actual: NESCU.indexOf' (Pattern "") 0 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.indexOf' (Pattern "") 0 (nes (Proxy :: Proxy "ab")) , expected: Just 0 } assertEqual - { actual: NESCU.indexOf' (Pattern "") 1 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.indexOf' (Pattern "") 1 (nes (Proxy :: Proxy "ab")) , expected: Just 1 } assertEqual - { actual: NESCU.indexOf' (Pattern "") 2 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.indexOf' (Pattern "") 2 (nes (Proxy :: Proxy "ab")) , expected: Just 2 } assertEqual - { actual: NESCU.indexOf' (Pattern "") 3 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.indexOf' (Pattern "") 3 (nes (Proxy :: Proxy "ab")) , expected: Nothing } assertEqual - { actual: NESCU.indexOf' (Pattern "bc") 0 (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.indexOf' (Pattern "bc") 0 (nes (Proxy :: Proxy "abcd")) , expected: Just 1 } assertEqual - { actual: NESCU.indexOf' (Pattern "bc") 1 (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.indexOf' (Pattern "bc") 1 (nes (Proxy :: Proxy "abcd")) , expected: Just 1 } assertEqual - { actual: NESCU.indexOf' (Pattern "bc") 2 (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.indexOf' (Pattern "bc") 2 (nes (Proxy :: Proxy "abcd")) , expected: Nothing } assertEqual - { actual: NESCU.indexOf' (Pattern "cb") 0 (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.indexOf' (Pattern "cb") 0 (nes (Proxy :: Proxy "abcd")) , expected: Nothing } log "lastIndexOf" assertEqual - { actual: NESCU.lastIndexOf (Pattern "") (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.lastIndexOf (Pattern "") (nes (Proxy :: Proxy "abcd")) , expected: Just 4 } assertEqual - { actual: NESCU.lastIndexOf (Pattern "bc") (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.lastIndexOf (Pattern "bc") (nes (Proxy :: Proxy "abcd")) , expected: Just 1 } assertEqual - { actual: NESCU.lastIndexOf (Pattern "cb") (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.lastIndexOf (Pattern "cb") (nes (Proxy :: Proxy "abcd")) , expected: Nothing } log "lastIndexOf'" assertEqual - { actual: NESCU.lastIndexOf' (Pattern "") (-1) (nes (SProxy :: SProxy "ab")) + { actual: NESCU.lastIndexOf' (Pattern "") (-1) (nes (Proxy :: Proxy "ab")) , expected: Nothing } assertEqual - { actual: NESCU.lastIndexOf' (Pattern "") 0 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.lastIndexOf' (Pattern "") 0 (nes (Proxy :: Proxy "ab")) , expected: Just 0 } assertEqual - { actual: NESCU.lastIndexOf' (Pattern "") 1 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.lastIndexOf' (Pattern "") 1 (nes (Proxy :: Proxy "ab")) , expected: Just 1 } assertEqual - { actual: NESCU.lastIndexOf' (Pattern "") 2 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.lastIndexOf' (Pattern "") 2 (nes (Proxy :: Proxy "ab")) , expected: Just 2 } assertEqual - { actual: NESCU.lastIndexOf' (Pattern "") 3 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.lastIndexOf' (Pattern "") 3 (nes (Proxy :: Proxy "ab")) , expected: Nothing } assertEqual - { actual: NESCU.lastIndexOf' (Pattern "bc") 0 (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.lastIndexOf' (Pattern "bc") 0 (nes (Proxy :: Proxy "abcd")) , expected: Nothing } assertEqual - { actual: NESCU.lastIndexOf' (Pattern "bc") 1 (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.lastIndexOf' (Pattern "bc") 1 (nes (Proxy :: Proxy "abcd")) , expected: Just 1 } assertEqual - { actual: NESCU.lastIndexOf' (Pattern "bc") 2 (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.lastIndexOf' (Pattern "bc") 2 (nes (Proxy :: Proxy "abcd")) , expected: Just 1 } assertEqual - { actual: NESCU.lastIndexOf' (Pattern "cb") 0 (nes (SProxy :: SProxy "abcd")) + { actual: NESCU.lastIndexOf' (Pattern "cb") 0 (nes (Proxy :: Proxy "abcd")) , expected: Nothing } log "length" assertEqual - { actual: NESCU.length (nes (SProxy :: SProxy "a")) + { actual: NESCU.length (nes (Proxy :: Proxy "a")) , expected: 1 } assertEqual - { actual: NESCU.length (nes (SProxy :: SProxy "ab")) + { actual: NESCU.length (nes (Proxy :: Proxy "ab")) , expected: 2 } log "take" assertEqual - { actual: NESCU.take 0 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.take 0 (nes (Proxy :: Proxy "ab")) , expected: Nothing } assertEqual - { actual: NESCU.take 1 (nes (SProxy :: SProxy "ab")) - , expected: Just (nes (SProxy :: SProxy "a")) + { actual: NESCU.take 1 (nes (Proxy :: Proxy "ab")) + , expected: Just (nes (Proxy :: Proxy "a")) } assertEqual - { actual: NESCU.take 2 (nes (SProxy :: SProxy "ab")) - , expected: Just (nes (SProxy :: SProxy "ab")) + { actual: NESCU.take 2 (nes (Proxy :: Proxy "ab")) + , expected: Just (nes (Proxy :: Proxy "ab")) } assertEqual - { actual: NESCU.take 3 (nes (SProxy :: SProxy "ab")) - , expected: Just (nes (SProxy :: SProxy "ab")) + { actual: NESCU.take 3 (nes (Proxy :: Proxy "ab")) + , expected: Just (nes (Proxy :: Proxy "ab")) } assertEqual - { actual: NESCU.take (-1) (nes (SProxy :: SProxy "ab")) + { actual: NESCU.take (-1) (nes (Proxy :: Proxy "ab")) , expected: Nothing } log "takeRight" assertEqual - { actual: NESCU.takeRight 0 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.takeRight 0 (nes (Proxy :: Proxy "ab")) , expected: Nothing } assertEqual - { actual: NESCU.takeRight 1 (nes (SProxy :: SProxy "ab")) - , expected: Just (nes (SProxy :: SProxy "b")) + { actual: NESCU.takeRight 1 (nes (Proxy :: Proxy "ab")) + , expected: Just (nes (Proxy :: Proxy "b")) } assertEqual - { actual: NESCU.takeRight 2 (nes (SProxy :: SProxy "ab")) - , expected: Just (nes (SProxy :: SProxy "ab")) + { actual: NESCU.takeRight 2 (nes (Proxy :: Proxy "ab")) + , expected: Just (nes (Proxy :: Proxy "ab")) } assertEqual - { actual: NESCU.takeRight 3 (nes (SProxy :: SProxy "ab")) - , expected: Just (nes (SProxy :: SProxy "ab")) + { actual: NESCU.takeRight 3 (nes (Proxy :: Proxy "ab")) + , expected: Just (nes (Proxy :: Proxy "ab")) } assertEqual - { actual: NESCU.takeRight (-1) (nes (SProxy :: SProxy "ab")) + { actual: NESCU.takeRight (-1) (nes (Proxy :: Proxy "ab")) , expected: Nothing } log "drop" assertEqual - { actual: NESCU.drop 0 (nes (SProxy :: SProxy "ab")) - , expected: Just (nes (SProxy :: SProxy "ab")) + { actual: NESCU.drop 0 (nes (Proxy :: Proxy "ab")) + , expected: Just (nes (Proxy :: Proxy "ab")) } assertEqual - { actual: NESCU.drop 1 (nes (SProxy :: SProxy "ab")) - , expected: Just (nes (SProxy :: SProxy "b")) + { actual: NESCU.drop 1 (nes (Proxy :: Proxy "ab")) + , expected: Just (nes (Proxy :: Proxy "b")) } assertEqual - { actual: NESCU.drop 2 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.drop 2 (nes (Proxy :: Proxy "ab")) , expected: Nothing } assertEqual - { actual: NESCU.drop 3 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.drop 3 (nes (Proxy :: Proxy "ab")) , expected: Nothing } assertEqual - { actual: NESCU.drop (-1) (nes (SProxy :: SProxy "ab")) - , expected: Just (nes (SProxy :: SProxy "ab")) + { actual: NESCU.drop (-1) (nes (Proxy :: Proxy "ab")) + , expected: Just (nes (Proxy :: Proxy "ab")) } log "dropRight" assertEqual - { actual: NESCU.dropRight 0 (nes (SProxy :: SProxy "ab")) - , expected: Just (nes (SProxy :: SProxy "ab")) + { actual: NESCU.dropRight 0 (nes (Proxy :: Proxy "ab")) + , expected: Just (nes (Proxy :: Proxy "ab")) } assertEqual - { actual: NESCU.dropRight 1 (nes (SProxy :: SProxy "ab")) - , expected: Just (nes (SProxy :: SProxy "a")) + { actual: NESCU.dropRight 1 (nes (Proxy :: Proxy "ab")) + , expected: Just (nes (Proxy :: Proxy "a")) } assertEqual - { actual: NESCU.dropRight 2 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.dropRight 2 (nes (Proxy :: Proxy "ab")) , expected: Nothing } assertEqual - { actual: NESCU.dropRight 3 (nes (SProxy :: SProxy "ab")) + { actual: NESCU.dropRight 3 (nes (Proxy :: Proxy "ab")) , expected: Nothing } assertEqual - { actual: NESCU.dropRight (-1) (nes (SProxy :: SProxy "ab")) - , expected: Just (nes (SProxy :: SProxy "ab")) + { actual: NESCU.dropRight (-1) (nes (Proxy :: Proxy "ab")) + , expected: Just (nes (Proxy :: Proxy "ab")) } log "countPrefix" assertEqual - { actual: NESCU.countPrefix (_ == 'a') (nes (SProxy :: SProxy "ab")) + { actual: NESCU.countPrefix (_ == 'a') (nes (Proxy :: Proxy "ab")) , expected: 1 } assertEqual - { actual: NESCU.countPrefix (_ == 'a') (nes (SProxy :: SProxy "aaab")) + { actual: NESCU.countPrefix (_ == 'a') (nes (Proxy :: Proxy "aaab")) , expected: 3 } assertEqual - { actual: NESCU.countPrefix (_ == 'a') (nes (SProxy :: SProxy "abaa")) + { actual: NESCU.countPrefix (_ == 'a') (nes (Proxy :: Proxy "abaa")) , expected: 1 } assertEqual - { actual: NESCU.countPrefix (_ == 'c') (nes (SProxy :: SProxy "abaa")) + { actual: NESCU.countPrefix (_ == 'c') (nes (Proxy :: Proxy "abaa")) , expected: 0 } log "splitAt" assertEqual - { actual: NESCU.splitAt 0 (nes (SProxy :: SProxy "a")) - , expected: { before: Nothing, after: Just (nes (SProxy :: SProxy "a")) } + { actual: NESCU.splitAt 0 (nes (Proxy :: Proxy "a")) + , expected: { before: Nothing, after: Just (nes (Proxy :: Proxy "a")) } } assertEqual - { actual: NESCU.splitAt 1 (nes (SProxy :: SProxy "ab")) - , expected: { before: Just (nes (SProxy :: SProxy "a")), after: Just (nes (SProxy :: SProxy "b")) } + { actual: NESCU.splitAt 1 (nes (Proxy :: Proxy "ab")) + , expected: { before: Just (nes (Proxy :: Proxy "a")), after: Just (nes (Proxy :: Proxy "b")) } } assertEqual - { actual: NESCU.splitAt 3 (nes (SProxy :: SProxy "aabcc")) - , expected: { before: Just (nes (SProxy :: SProxy "aab")), after: Just (nes (SProxy :: SProxy "cc")) } + { actual: NESCU.splitAt 3 (nes (Proxy :: Proxy "aabcc")) + , expected: { before: Just (nes (Proxy :: Proxy "aab")), after: Just (nes (Proxy :: Proxy "cc")) } } assertEqual - { actual: NESCU.splitAt (-1) (nes (SProxy :: SProxy "abc")) - , expected: { before: Nothing, after: Just (nes (SProxy :: SProxy "abc")) } + { actual: NESCU.splitAt (-1) (nes (Proxy :: Proxy "abc")) + , expected: { before: Nothing, after: Just (nes (Proxy :: Proxy "abc")) } } nea :: Array ~> NEA.NonEmptyArray From e897bb707acf3ae512d1dce12d2d79c585a03f72 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Thu, 26 Nov 2020 12:30:03 -0800 Subject: [PATCH 05/26] Use coerce instead of unsafeCoerce where appropriate (#130) * Replace unsafeCoerce with safer alternative where possible * Remove unused import * Add docs to the Internal module and NonEmptyString constructor * Remove 'usage of this constructor...' sentence * Move constructor docs to type docs Constructor docs don't yet appear in the generated documentation * Add backticks around NonEmptyString in docs * Add "For internal use only. Do not export" above to/fromNEString & listS --- src/Data/String/NonEmpty/CodePoints.purs | 12 +++++++----- src/Data/String/NonEmpty/CodeUnits.purs | 11 +++++++---- src/Data/String/NonEmpty/Internal.purs | 12 ++++++++++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Data/String/NonEmpty/CodePoints.purs b/src/Data/String/NonEmpty/CodePoints.purs index 5357851..7b5328a 100644 --- a/src/Data/String/NonEmpty/CodePoints.purs +++ b/src/Data/String/NonEmpty/CodePoints.purs @@ -33,19 +33,21 @@ import Data.Semigroup.Foldable (class Foldable1) import Data.Semigroup.Foldable as F1 import Data.String.CodePoints (CodePoint) import Data.String.CodePoints as CP -import Data.String.NonEmpty.Internal (NonEmptyString, fromString) +import Data.String.NonEmpty.Internal (NonEmptyString(..), fromString) import Data.String.Pattern (Pattern) import Partial.Unsafe (unsafePartial) -import Unsafe.Coerce (unsafeCoerce) +-- For internal use only. Do not export. toNonEmptyString :: String -> NonEmptyString -toNonEmptyString = unsafeCoerce +toNonEmptyString = NonEmptyString +-- For internal use only. Do not export. fromNonEmptyString :: NonEmptyString -> String -fromNonEmptyString = unsafeCoerce +fromNonEmptyString (NonEmptyString s) = s +-- For internal use only. Do not export. liftS :: forall r. (String -> r) -> NonEmptyString -> r -liftS = unsafeCoerce +liftS f (NonEmptyString s) = f s fromCodePointArray :: Array CodePoint -> Maybe NonEmptyString fromCodePointArray = case _ of diff --git a/src/Data/String/NonEmpty/CodeUnits.purs b/src/Data/String/NonEmpty/CodeUnits.purs index 2aa0a6c..d22e180 100644 --- a/src/Data/String/NonEmpty/CodeUnits.purs +++ b/src/Data/String/NonEmpty/CodeUnits.purs @@ -33,20 +33,23 @@ import Data.Maybe (Maybe(..), fromJust) import Data.Semigroup.Foldable (class Foldable1) import Data.Semigroup.Foldable as F1 import Data.String.CodeUnits as CU -import Data.String.NonEmpty.Internal (NonEmptyString, fromString) +import Data.String.NonEmpty.Internal (NonEmptyString(..), fromString) import Data.String.Pattern (Pattern) import Data.String.Unsafe as U import Partial.Unsafe (unsafePartial) import Unsafe.Coerce (unsafeCoerce) +-- For internal use only. Do not export. toNonEmptyString :: String -> NonEmptyString -toNonEmptyString = unsafeCoerce +toNonEmptyString = NonEmptyString +-- For internal use only. Do not export. fromNonEmptyString :: NonEmptyString -> String -fromNonEmptyString = unsafeCoerce +fromNonEmptyString (NonEmptyString s) = s +-- For internal use only. Do not export. liftS :: forall r. (String -> r) -> NonEmptyString -> r -liftS = unsafeCoerce +liftS f (NonEmptyString s) = f s -- | Creates a `NonEmptyString` from a character array `String`, returning -- | `Nothing` if the input is empty. diff --git a/src/Data/String/NonEmpty/Internal.purs b/src/Data/String/NonEmpty/Internal.purs index 7a6197e..707b779 100644 --- a/src/Data/String/NonEmpty/Internal.purs +++ b/src/Data/String/NonEmpty/Internal.purs @@ -1,3 +1,9 @@ +-- | While most of the code in this module is safe, this module does +-- | export a few partial functions and the `NonEmptyString` constructor. +-- | While the partial functions are obvious from the `Partial` constraint in +-- | their type signature, the `NonEmptyString` constructor can be overlooked +-- | when searching for issues in one's code. See the constructor's +-- | documentation for more information. module Data.String.NonEmpty.Internal where import Prelude @@ -13,6 +19,12 @@ import Prim.TypeError as TE import Unsafe.Coerce (unsafeCoerce) -- | A string that is known not to be empty. +-- | +-- | You can use this constructor to create a `NonEmptyString` that isn't +-- | non-empty, breaking the guarantee behind this newtype. It is +-- | provided as an escape hatch mainly for the `Data.NonEmpty.CodeUnits` +-- | and `Data.NonEmpty.CodePoints` modules. Use this at your own risk +-- | when you know what you are doing. newtype NonEmptyString = NonEmptyString String derive newtype instance eqNonEmptyString ∷ Eq NonEmptyString From 52cae45a69c8b4e6c6061e35e677b8079b389a9c Mon Sep 17 00:00:00 2001 From: Emiel van de Laar Date: Wed, 2 Dec 2020 19:46:12 +0100 Subject: [PATCH 06/26] Remove references to `codePointToInt` (#135) The `codePointToInt` function is no longer available but is still referenced in a few documentation examples. Here we replace it with `fromEnum`. --- src/Data/String/CodePoints.purs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Data/String/CodePoints.purs b/src/Data/String/CodePoints.purs index 9083c10..82d263c 100644 --- a/src/Data/String/CodePoints.purs +++ b/src/Data/String/CodePoints.purs @@ -220,7 +220,7 @@ length = Array.length <<< toCodePointArray -- | time linear to the length of the string. -- | -- | ```purescript --- | >>> countPrefix (\c -> codePointToInt c == 0x1D400) "𝐀𝐀 b c 𝐀" +-- | >>> countPrefix (\c -> fromEnum c == 0x1D400) "𝐀𝐀 b c 𝐀" -- | 2 -- | ``` -- | @@ -329,7 +329,7 @@ takeFallback n s = case uncons s of -- | in time linear to the length of the string. -- | -- | ```purescript --- | >>> takeWhile (\c -> codePointToInt c == 0x1D400) "𝐀𝐀 b c 𝐀" +-- | >>> takeWhile (\c -> fromEnum c == 0x1D400) "𝐀𝐀 b c 𝐀" -- | "𝐀𝐀" -- | ``` -- | @@ -356,7 +356,7 @@ drop n s = CU.drop (CU.length (take n s)) s -- | to the length of the string. -- | -- | ```purescript --- | >>> dropWhile (\c -> codePointToInt c == 0x1D400) "𝐀𝐀 b c 𝐀" +-- | >>> dropWhile (\c -> fromEnum c == 0x1D400) "𝐀𝐀 b c 𝐀" -- | " b c 𝐀" -- | ``` -- | From dcbd6cf859b4d7e432c36e49f3bc1048ef206307 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Sat, 5 Dec 2020 07:33:57 -0800 Subject: [PATCH 07/26] Migrate to GitHub Actions and update installation instructions. (#136) --- .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++++++ .gitignore | 2 +- .travis.yml | 24 ------------------------ README.md | 4 ++-- 4 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e2972ba --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: CI + +on: push + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: purescript-contrib/setup-purescript@main + with: + purescript: "0.14.0-rc3" + + - uses: actions/setup-node@v1 + with: + node-version: "12" + + - name: Install dependencies + run: | + npm install -g bower + npm install + bower install --production + + - name: Build source + run: npm run-script build + + - name: Run tests + run: | + bower install + npm run-script test --if-present diff --git a/.gitignore b/.gitignore index 332b6cf..b846b63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /.* !/.gitignore !/.eslintrc.json -!/.travis.yml +!/.github/ /bower_components/ /node_modules/ /output/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 116705f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -language: node_js -dist: trusty -sudo: required -node_js: stable -env: - - PATH=$HOME/purescript:$PATH -install: - # - TAG=$(basename $(curl --location --silent --output /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest)) - - TAG=v0.14.0-rc3 - - curl --location --output $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz - - tar -xvf $HOME/purescript.tar.gz -C $HOME/ - - chmod a+x $HOME/purescript - - npm install -g bower - - npm install -script: - - bower install --production - - npm run -s build - - bower install - - npm -s test -after_success: -- >- - test $TRAVIS_TAG && - echo $GITHUB_TOKEN | pulp login && - echo y | pulp publish --no-push diff --git a/README.md b/README.md index 0565699..62fa5a9 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # purescript-strings [![Latest release](http://img.shields.io/github/release/purescript/purescript-strings.svg)](https://github.com/purescript/purescript-strings/releases) -[![Build status](https://travis-ci.org/purescript/purescript-strings.svg?branch=master)](https://travis-ci.org/purescript/purescript-strings) +[![Build status](https://github.com/purescript/purescript-strings/workflows/CI/badge.svg?branch=master)](https://github.com/purescript/purescript-strings/actions?query=workflow%3ACI+branch%3Amaster) String and char utility functions, regular expressions. ## Installation ``` -bower install purescript-strings +spago install strings ``` ## Documentation From f1082da572c966e5b965e83d1ab1c40f5fe3b9e6 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Mon, 7 Dec 2020 20:22:51 -0800 Subject: [PATCH 08/26] Run CI on push / pull_request to master --- .github/workflows/ci.yml | 6 +++++- README.md | 1 + package.json | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2972ba..55efa3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,10 @@ name: CI -on: push +on: + push: + branches: [master] + pull_request: + branches: [master] jobs: build: diff --git a/README.md b/README.md index 62fa5a9..73292c1 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Latest release](http://img.shields.io/github/release/purescript/purescript-strings.svg)](https://github.com/purescript/purescript-strings/releases) [![Build status](https://github.com/purescript/purescript-strings/workflows/CI/badge.svg?branch=master)](https://github.com/purescript/purescript-strings/actions?query=workflow%3ACI+branch%3Amaster) +[![Pursuit](https://pursuit.purescript.org/packages/purescript-strings/badge)](https://pursuit.purescript.org/packages/purescript-strings) String and char utility functions, regular expressions. diff --git a/package.json b/package.json index 1f09388..c116cae 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,9 @@ "bench": "npm run bench:build && npm run bench:run" }, "devDependencies": { - "eslint": "^4.19.1", + "eslint": "^7.15.0", "pulp": "^15.0.0", "purescript-psa": "^0.8.0", - "rimraf": "^2.6.2" + "rimraf": "^3.0.2" } } From 7a94736df8575cdcf456c60b1554e652f58bba63 Mon Sep 17 00:00:00 2001 From: Cyril Date: Sat, 19 Dec 2020 02:26:34 +0100 Subject: [PATCH 09/26] Remove the bounds check from the foreign implementation of lastIndexOf' (#137) * Remove the bounds check from the foreign implementation of lastIndexOf' * Update lastIndexOf' documentation --- src/Data/String/CodePoints.purs | 14 +++++++++++++- src/Data/String/CodeUnits.js | 1 - src/Data/String/CodeUnits.purs | 11 +++++++++-- src/Data/String/NonEmpty/CodeUnits.purs | 11 +++++++++-- test/Test/Data/String/CodePoints.purs | 8 ++++++++ test/Test/Data/String/CodeUnits.purs | 4 ++-- test/Test/Data/String/NonEmpty/CodeUnits.purs | 4 ++-- 7 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/Data/String/CodePoints.purs b/src/Data/String/CodePoints.purs index 82d263c..7d0f528 100644 --- a/src/Data/String/CodePoints.purs +++ b/src/Data/String/CodePoints.purs @@ -286,11 +286,23 @@ lastIndexOf p s = (\i -> length (CU.take i s)) <$> CU.lastIndexOf p s -- | Returns the number of code points preceding the first match of the given -- | pattern in the string. Pattern matches following the given index will be --- | ignored. Returns Nothing when no matches are found. +-- | ignored. +-- | +-- | Giving a negative index is equivalent to giving 0 and giving an index +-- | greater than the number of code points in the string is equivalent to +-- | searching in the whole string. +-- | +-- | Returns Nothing when no matches are found. -- | -- | ```purescript +-- | >>> lastIndexOf' (Pattern "𝐀") (-1) "b 𝐀𝐀 c 𝐀" +-- | Nothing +-- | >>> lastIndexOf' (Pattern "𝐀") 0 "b 𝐀𝐀 c 𝐀" +-- | Nothing -- | >>> lastIndexOf' (Pattern "𝐀") 5 "b 𝐀𝐀 c 𝐀" -- | Just 3 +-- | >>> lastIndexOf' (Pattern "𝐀") 8 "b 𝐀𝐀 c 𝐀" +-- | Just 7 -- | >>> lastIndexOf' (Pattern "o") 5 "b 𝐀𝐀 c 𝐀" -- | Nothing -- | ``` diff --git a/src/Data/String/CodeUnits.js b/src/Data/String/CodeUnits.js index 870b96f..6017fd3 100644 --- a/src/Data/String/CodeUnits.js +++ b/src/Data/String/CodeUnits.js @@ -83,7 +83,6 @@ exports._lastIndexOfStartingAt = function (just) { return function (x) { return function (startAt) { return function (s) { - if (startAt < 0 || startAt > s.length) return nothing; var i = s.lastIndexOf(x, startAt); return i === -1 ? nothing : just(i); }; diff --git a/src/Data/String/CodeUnits.purs b/src/Data/String/CodeUnits.purs index cc919e0..dfa0482 100644 --- a/src/Data/String/CodeUnits.purs +++ b/src/Data/String/CodeUnits.purs @@ -215,14 +215,21 @@ foreign import _lastIndexOf -> Maybe Int -- | Returns the index of the last occurrence of the pattern in the --- | given string, starting at the specified index --- | and searching backwards towards the beginning of the string. +-- | given string, starting at the specified index and searching +-- | backwards towards the beginning of the string. +-- | +-- | Starting at a negative index is equivalent to starting at 0 and +-- | starting at an index greater than the string length is equivalent +-- | to searching in the whole string. +-- | -- | Returns `Nothing` if there is no match. -- | -- | ```purescript +-- | lastIndexOf' (Pattern "a") (-1) "ababa" == Just 0 -- | lastIndexOf' (Pattern "a") 1 "ababa" == Just 0 -- | lastIndexOf' (Pattern "a") 3 "ababa" == Just 2 -- | lastIndexOf' (Pattern "a") 4 "ababa" == Just 4 +-- | lastIndexOf' (Pattern "a") 5 "ababa" == Just 4 -- | ``` -- | lastIndexOf' :: Pattern -> Int -> String -> Maybe Int diff --git a/src/Data/String/NonEmpty/CodeUnits.purs b/src/Data/String/NonEmpty/CodeUnits.purs index d22e180..af3de43 100644 --- a/src/Data/String/NonEmpty/CodeUnits.purs +++ b/src/Data/String/NonEmpty/CodeUnits.purs @@ -159,14 +159,21 @@ lastIndexOf :: Pattern -> NonEmptyString -> Maybe Int lastIndexOf = liftS <<< CU.lastIndexOf -- | Returns the index of the last occurrence of the pattern in the --- | given string, starting at the specified index --- | and searching backwards towards the beginning of the string. +-- | given string, starting at the specified index and searching +-- | backwards towards the beginning of the string. +-- | +-- | Starting at a negative index is equivalent to starting at 0 and +-- | starting at an index greater than the string length is equivalent +-- | to searching in the whole string. +-- | -- | Returns `Nothing` if there is no match. -- | -- | ```purescript +-- | lastIndexOf' (Pattern "a") (-1) (NonEmptyString "ababa") == Just 0 -- | lastIndexOf' (Pattern "a") 1 (NonEmptyString "ababa") == Just 0 -- | lastIndexOf' (Pattern "a") 3 (NonEmptyString "ababa") == Just 2 -- | lastIndexOf' (Pattern "a") 4 (NonEmptyString "ababa") == Just 4 +-- | lastIndexOf' (Pattern "a") 5 (NonEmptyString "ababa") == Just 4 -- | ``` lastIndexOf' :: Pattern -> Int -> NonEmptyString -> Maybe Int lastIndexOf' pat = liftS <<< CU.lastIndexOf' pat diff --git a/test/Test/Data/String/CodePoints.purs b/test/Test/Data/String/CodePoints.purs index 310321b..587ec89 100644 --- a/test/Test/Data/String/CodePoints.purs +++ b/test/Test/Data/String/CodePoints.purs @@ -366,6 +366,10 @@ testStringCodePoints = do { actual: SCP.lastIndexOf' (Pattern str) 1 str , expected: Just 0 } + assertEqual + { actual: SCP.lastIndexOf' (Pattern "a") (-1) str + , expected: Just 0 + } assertEqual { actual: SCP.lastIndexOf' (Pattern "a") 0 str , expected: Just 0 @@ -374,6 +378,10 @@ testStringCodePoints = do { actual: SCP.lastIndexOf' (Pattern "a") 7 str , expected: Just 0 } + assertEqual + { actual: SCP.lastIndexOf' (Pattern "a") (SCP.length str) str + , expected: Just 0 + } assertEqual { actual: SCP.lastIndexOf' (Pattern "z") 0 str , expected: Nothing diff --git a/test/Test/Data/String/CodeUnits.purs b/test/Test/Data/String/CodeUnits.purs index 249a639..9cf010b 100644 --- a/test/Test/Data/String/CodeUnits.purs +++ b/test/Test/Data/String/CodeUnits.purs @@ -270,7 +270,7 @@ testStringCodeUnits = do } assertEqual { actual: SCU.lastIndexOf' (Pattern "") (-1) "ab" - , expected: Nothing + , expected: Just 0 } assertEqual { actual: SCU.lastIndexOf' (Pattern "") 0 "ab" @@ -286,7 +286,7 @@ testStringCodeUnits = do } assertEqual { actual: SCU.lastIndexOf' (Pattern "") 3 "ab" - , expected: Nothing + , expected: Just 2 } assertEqual { actual: SCU.lastIndexOf' (Pattern "bc") 0 "abcd" diff --git a/test/Test/Data/String/NonEmpty/CodeUnits.purs b/test/Test/Data/String/NonEmpty/CodeUnits.purs index 0e78ee8..9a33b0c 100644 --- a/test/Test/Data/String/NonEmpty/CodeUnits.purs +++ b/test/Test/Data/String/NonEmpty/CodeUnits.purs @@ -277,7 +277,7 @@ testNonEmptyStringCodeUnits = do log "lastIndexOf'" assertEqual { actual: NESCU.lastIndexOf' (Pattern "") (-1) (nes (Proxy :: Proxy "ab")) - , expected: Nothing + , expected: Just 0 } assertEqual { actual: NESCU.lastIndexOf' (Pattern "") 0 (nes (Proxy :: Proxy "ab")) @@ -293,7 +293,7 @@ testNonEmptyStringCodeUnits = do } assertEqual { actual: NESCU.lastIndexOf' (Pattern "") 3 (nes (Proxy :: Proxy "ab")) - , expected: Nothing + , expected: Just 2 } assertEqual { actual: NESCU.lastIndexOf' (Pattern "bc") 0 (nes (Proxy :: Proxy "abcd")) From 3de404e1b99e07f1b1d648981879a16fcfff370d Mon Sep 17 00:00:00 2001 From: fujisawa Date: Thu, 24 Dec 2020 06:21:00 +0900 Subject: [PATCH 10/26] Add dotAll regexp flag (#133) --- src/Data/String/Regex.js | 1 + src/Data/String/Regex.purs | 2 ++ src/Data/String/Regex/Flags.purs | 21 +++++++++++++++++++++ test/Test/Data/String/Regex.purs | 3 ++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Data/String/Regex.js b/src/Data/String/Regex.js index ae40c11..8a3a473 100644 --- a/src/Data/String/Regex.js +++ b/src/Data/String/Regex.js @@ -27,6 +27,7 @@ exports.flagsImpl = function (r) { multiline: r.multiline, ignoreCase: r.ignoreCase, global: r.global, + dotAll: r.dotAll, sticky: !!r.sticky, unicode: !!r.unicode }; diff --git a/src/Data/String/Regex.purs b/src/Data/String/Regex.purs index 4f2e74f..43ebf21 100644 --- a/src/Data/String/Regex.purs +++ b/src/Data/String/Regex.purs @@ -61,6 +61,7 @@ renderFlags (RegexFlags f) = (if f.global then "g" else "") <> (if f.ignoreCase then "i" else "") <> (if f.multiline then "m" else "") <> + (if f.dotAll then "s" else "") <> (if f.sticky then "y" else "") <> (if f.unicode then "u" else "") @@ -70,6 +71,7 @@ parseFlags s = RegexFlags { global: contains (Pattern "g") s , ignoreCase: contains (Pattern "i") s , multiline: contains (Pattern "m") s + , dotAll: contains (Pattern "s") s , sticky: contains (Pattern "y") s , unicode: contains (Pattern "u") s } diff --git a/src/Data/String/Regex/Flags.purs b/src/Data/String/Regex/Flags.purs index bd14d8c..dc7a0c7 100644 --- a/src/Data/String/Regex/Flags.purs +++ b/src/Data/String/Regex/Flags.purs @@ -9,6 +9,7 @@ type RegexFlagsRec = { global :: Boolean , ignoreCase :: Boolean , multiline :: Boolean + , dotAll :: Boolean , sticky :: Boolean , unicode :: Boolean } @@ -22,6 +23,7 @@ noFlags = RegexFlags { global: false , ignoreCase: false , multiline: false + , dotAll : false , sticky: false , unicode: false } @@ -32,6 +34,7 @@ global = RegexFlags { global: true , ignoreCase: false , multiline: false + , dotAll : false , sticky: false , unicode: false } @@ -42,6 +45,7 @@ ignoreCase = RegexFlags { global: false , ignoreCase: true , multiline: false + , dotAll : false , sticky: false , unicode: false } @@ -52,6 +56,7 @@ multiline = RegexFlags { global: false , ignoreCase: false , multiline: true + , dotAll : false , sticky: false , unicode: false } @@ -62,6 +67,7 @@ sticky = RegexFlags { global: false , ignoreCase: false , multiline: false + , dotAll : false , sticky: true , unicode: false } @@ -72,15 +78,28 @@ unicode = RegexFlags { global: false , ignoreCase: false , multiline: false + , dotAll : false , sticky: false , unicode: true } +-- | Only dotAll flag set to true +dotAll :: RegexFlags +dotAll = RegexFlags + { global: false + , ignoreCase: false + , multiline: false + , dotAll : true + , sticky: false + , unicode: false + } + instance semigroupRegexFlags :: Semigroup RegexFlags where append (RegexFlags x) (RegexFlags y) = RegexFlags { global: x.global || y.global , ignoreCase: x.ignoreCase || y.ignoreCase , multiline: x.multiline || y.multiline + , dotAll: x.dotAll || y.dotAll , sticky: x.sticky || y.sticky , unicode: x.unicode || y.unicode } @@ -93,6 +112,7 @@ instance eqRegexFlags :: Eq RegexFlags where = x.global == y.global && x.ignoreCase == y.ignoreCase && x.multiline == y.multiline + && x.dotAll == y.dotAll && x.sticky == y.sticky && x.unicode == y.unicode @@ -104,6 +124,7 @@ instance showRegexFlags :: Show RegexFlags where <> (guard flags.global $> "global") <> (guard flags.ignoreCase $> "ignoreCase") <> (guard flags.multiline $> "multiline") + <> (guard flags.dotAll $> "dotAll") <> (guard flags.sticky $> "sticky") <> (guard flags.unicode $> "unicode") in diff --git a/test/Test/Data/String/Regex.purs b/test/Test/Data/String/Regex.purs index 326b35e..a458759 100644 --- a/test/Test/Data/String/Regex.purs +++ b/test/Test/Data/String/Regex.purs @@ -5,7 +5,7 @@ import Data.String.Regex import Data.Array.NonEmpty (NonEmptyArray, fromArray) import Data.Either (isLeft) import Data.Maybe (Maybe(..), fromJust) -import Data.String.Regex.Flags (global, ignoreCase, noFlags) +import Data.String.Regex.Flags (dotAll, global, ignoreCase, noFlags) import Data.String.Regex.Unsafe (unsafeRegex) import Effect (Effect) import Effect.Console (log) @@ -24,6 +24,7 @@ testStringRegex = do assert $ "quxbarfoobaz" == replace (unsafeRegex "foo" noFlags) "qux" "foobarfoobaz" assert $ "quxbarquxbaz" == replace (unsafeRegex "foo" global) "qux" "foobarfoobaz" assert $ "quxbarquxbaz" == replace (unsafeRegex "foo" (global <> ignoreCase)) "qux" "foobarFOObaz" + assert $ "quxbarfoobaz" == replace (unsafeRegex ".foo" dotAll) "qux" "\nfoobarfoobaz" log "match" assert $ match (unsafeRegex "^abc$" noFlags) "abc" == Just (nea [Just "abc"]) From 5815ea91fafa623d99d703335d4645da748faa1b Mon Sep 17 00:00:00 2001 From: David Chambers Date: Wed, 6 Jan 2021 16:49:07 +0100 Subject: [PATCH 11/26] update replace' to reflect the existence of optional capturing groups (#126) * Update CI to use v0.14.0-rc5 * update replace' to reflect the existence of optional capturing groups Co-authored-by: Jordan Martinez --- .github/workflows/ci.yml | 2 +- src/Data/String/Regex.js | 21 +++++++++++++++------ src/Data/String/Regex.purs | 25 ++++++++++++++++--------- test/Test/Data/String/Regex.purs | 6 +++++- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55efa3d..f4f44e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: - uses: purescript-contrib/setup-purescript@main with: - purescript: "0.14.0-rc3" + purescript: "0.14.0-rc5" - uses: actions/setup-node@v1 with: diff --git a/src/Data/String/Regex.js b/src/Data/String/Regex.js index 8a3a473..b3be593 100644 --- a/src/Data/String/Regex.js +++ b/src/Data/String/Regex.js @@ -68,12 +68,21 @@ exports.replace = function (r) { }; }; -exports.replaceBy = function (r) { - return function (f) { - return function (s2) { - return s2.replace(r, function (match) { - return f(match)(Array.prototype.splice.call(arguments, 1, arguments.length - 3)); - }); +exports._replaceBy = function (just) { + return function (nothing) { + return function (r) { + return function (f) { + return function (s) { + return s.replace(r, function (match) { + var groups = []; + var group, i = 1; + while (typeof (group = arguments[i++]) !== "number") { + groups.push(group == null ? nothing : just(group)); + } + return f(match)(groups); + }); + }; + }; }; }; }; diff --git a/src/Data/String/Regex.purs b/src/Data/String/Regex.purs index 43ebf21..aae56e1 100644 --- a/src/Data/String/Regex.purs +++ b/src/Data/String/Regex.purs @@ -1,5 +1,5 @@ -- | Wraps Javascript's `RegExp` object that enables matching strings with --- | patternes defined by regular expressions. +-- | patterns defined by regular expressions. -- | For details of the underlying implementation, see [RegExp Reference at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp). module Data.String.Regex ( Regex(..) @@ -95,18 +95,25 @@ foreign import _match match :: Regex -> String -> Maybe (NonEmptyArray (Maybe String)) match = _match Just Nothing --- | Replaces occurences of the `Regex` with the first string. The replacement +-- | Replaces occurrences of the `Regex` with the first string. The replacement -- | string can include special replacement patterns escaped with `"$"`. -- | See [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace). foreign import replace :: Regex -> String -> String -> String --- | Transforms occurences of the `Regex` using a function of the matched --- | substring and a list of submatch strings. --- | See the [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter). -replace' :: Regex -> (String -> Array String -> String) -> String -> String -replace' = replaceBy +foreign import _replaceBy + :: (forall r. r -> Maybe r) + -> (forall r. Maybe r) + -> Regex + -> (String -> Array (Maybe String) -> String) + -> String + -> String -foreign import replaceBy :: Regex -> (String -> Array String -> String) -> String -> String +-- | Transforms occurrences of the `Regex` using a function of the matched +-- | substring and a list of captured substrings of type `Maybe String`, +-- | where `Nothing` represents an unmatched optional capturing group. +-- | See the [reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter). +replace' :: Regex -> (String -> Array (Maybe String) -> String) -> String -> String +replace' = _replaceBy Just Nothing foreign import _search :: (forall r. r -> Maybe r) @@ -120,5 +127,5 @@ foreign import _search search :: Regex -> String -> Maybe Int search = _search Just Nothing --- | Split the string into an array of substrings along occurences of the `Regex`. +-- | Split the string into an array of substrings along occurrences of the `Regex`. foreign import split :: Regex -> String -> Array String diff --git a/test/Test/Data/String/Regex.purs b/test/Test/Data/String/Regex.purs index a458759..01d583b 100644 --- a/test/Test/Data/String/Regex.purs +++ b/test/Test/Data/String/Regex.purs @@ -10,7 +10,7 @@ import Data.String.Regex.Unsafe (unsafeRegex) import Effect (Effect) import Effect.Console (log) import Partial.Unsafe (unsafePartial) -import Prelude (type (~>), Unit, discard, not, ($), (<<<), (<>), (==)) +import Prelude (type (~>), Unit, discard, not, show, ($), (<<<), (<>), (==)) import Test.Assert (assert) testStringRegex :: Effect Unit @@ -35,6 +35,10 @@ testStringRegex = do log "replace'" assert $ replace' (unsafeRegex "-" noFlags) (\s xs -> "!") "a-b-c" == "a!b-c" + assert $ replace' (unsafeRegex "(foo)(bar)?" noFlags) (\s xs -> show xs) "<>" == "<>" + assert $ replace' (unsafeRegex "(foo)(bar)?" noFlags) (\s xs -> show xs) "" == "<[(Just \"foo\"),Nothing]>" + assert $ replace' (unsafeRegex "(foo)(bar)?" noFlags) (\s xs -> show xs) "" == "<[(Just \"foo\"),(Just \"bar\")]>" + assert $ replace' (unsafeRegex "@(?\\w+)" noFlags) (\s xs -> show xs) "@purescript" == "[(Just \"purescript\")]" log "search" assert $ search (unsafeRegex "b" noFlags) "abc" == Just 1 From 6e27e114ac2b1672c730ba438826f0dec47ea300 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Sun, 10 Jan 2021 15:00:08 -0800 Subject: [PATCH 12/26] Generate changelog and add PR template (#140) * Generate CHANGELOG.md file using notes from previous GH releases * Add pull request template --- .github/PULL_REQUEST_TEMPLATE.md | 12 ++ CHANGELOG.md | 228 +++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 CHANGELOG.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..4435abb --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,12 @@ +**Description of the change** + +Clearly and concisely describe the purpose of the pull request. If this PR relates to an existing issue or change proposal, please link to it. Include any other background context that would help reviewers understand the motivation for this PR. + +--- + +**Checklist:** + +- [ ] Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)") +- [ ] Linked any existing issues or proposals that this pull request should close +- [ ] Updated or added relevant documentation +- [ ] Added a test for the contribution (if applicable) diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8cf568f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,228 @@ +# Changelog + +Notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +Breaking changes: + +New features: + +Bugfixes: + +Other improvements: + +## [v4.0.2](https://github.com/purescript/purescript-strings/releases/tag/v4.0.2) - 2020-05-13 + +- Improved performance for `stripPrefix` / `stripSuffix` (#123, @michaelficarra) + +## [v4.0.1](https://github.com/purescript/purescript-strings/releases/tag/v4.0.1) - 2018-11-11 + +- Fixed out of bounds access in `unsafeCodePointAt0Fallback` (@zyla) +- Fixed `slice` when end index equals string length (@abaco) + +## [v4.0.0](https://github.com/purescript/purescript-strings/releases/tag/v4.0.0) - 2018-05-23 + +- Updated for PureScript 0.12 +- `splitAt` now always returns a value (#78, @MonoidMusician) +- Added `slice` (@themattchan) +- Added more `String` `Gen`s to correspond with `Char` `Gen`s (@matthewleon) +- `Regex` `match` now returns `NonEmptyArray` +- All string functions now operate on code points now rather than code units. The old functions are available via the `.CodeUnits` modules +- `fromCharCode` can return `Nothing` now if given a value out of range + +## [v3.5.0](https://github.com/purescript/purescript-strings/releases/tag/v3.5.0) - 2018-02-12 + +- Added `Data.String.NonEmpty` + +## [v3.4.0](https://github.com/purescript/purescript-strings/releases/tag/v3.4.0) - 2017-12-28 + +* Add `Show CodePoint` instance (@csicar) +* Add `codePointFromChar` (@csicar) +* Expanded docs for most functions in `Data.String` and `Data.String.CodePoints` (@csicar) + +## [v3.3.2](https://github.com/purescript/purescript-strings/releases/tag/v3.3.2) - 2017-11-19 + +Performance improvement in `Data.String.Regex.match` (@fehrenbach) + +## [v3.3.1](https://github.com/purescript/purescript-strings/releases/tag/v3.3.1) - 2017-08-06 + +Fix some `Show` instances (@Rufflewind) + +## [v3.3.0](https://github.com/purescript/purescript-strings/releases/tag/v3.3.0) - 2017-07-10 + +* Add a new module `Data.String.CodePoints`, which treats strings as sequences of Unicode code points rather than sequences of UTF-16 code units. In the future we may swap this module with `Data.String`. (@michaelficarra) +* Fix a typo in the documentation (@ijks) + +## [v3.2.1](https://github.com/purescript/purescript-strings/releases/tag/v3.2.1) - 2017-06-06 + +- Ensure `genString` behaves the same regardless of the `MonadGen` implementation of `chooseInt` when `max < min` + +## [v3.2.0](https://github.com/purescript/purescript-strings/releases/tag/v3.2.0) - 2017-06-05 + +- Generated strings from `genString` now vary in length +- Added additional `Char` generators + +## [v3.1.0](https://github.com/purescript/purescript-strings/releases/tag/v3.1.0) - 2017-04-28 + +- Added some generator functions - introduced `Data.String.Gen` and `Data.Char.Gen` + +## [v3.0.0](https://github.com/purescript/purescript-strings/releases/tag/v3.0.0) - 2017-03-26 + +- Updated for PureScript 0.11 + +## [v2.1.0](https://github.com/purescript/purescript-strings/releases/tag/v2.1.0) - 2016-12-25 + +Add `unsafeRegex` (@rightfold) + +## [v2.0.2](https://github.com/purescript/purescript-strings/releases/tag/v2.0.2) - 2016-10-26 + +- Documentation fix for `split` #70 (@leighman) + +## [v2.0.1](https://github.com/purescript/purescript-strings/releases/tag/v2.0.1) - 2016-10-08 + +- Improved `null` check implementation (@Risto-Stevcev) + +## [v2.0.0](https://github.com/purescript/purescript-strings/releases/tag/v2.0.0) - 2016-10-08 + +- Updated dependencies +- `Pattern` and `Replacement` newtypes are now used to distinguish between arguments when a function accepts multiple strings +- `RegexFlags` have been reworked as a monoid (@Risto-Stevcev) + +## [v1.1.0](https://github.com/purescript/purescript-strings/releases/tag/v1.1.0) - 2016-07-20 + +- Restored export of the `count` function. + +## [v1.0.0](https://github.com/purescript/purescript-strings/releases/tag/v1.0.0) - 2016-06-01 + +This release is intended for the PureScript 0.9.1 compiler and newer. + +**Note**: The v1.0.0 tag is not meant to indicate the library is “finished”, the core libraries are all being bumped to this for the 0.9 compiler release so as to use semver more correctly. + +## [v1.0.0-rc.2](https://github.com/purescript/purescript-strings/releases/tag/v1.0.0-rc.2) - 2016-05-20 + +- Fix unused import warning + +## [v1.0.0-rc.1](https://github.com/purescript/purescript-strings/releases/tag/v1.0.0-rc.1) - 2016-03-24 + +- Release candidate for the psc 0.8+ core libraries + +## [v0.7.1](https://github.com/purescript/purescript-strings/releases/tag/v0.7.1) - 2015-11-20 + +- Removed unused imports (@tfausak) + +## [v0.7.0](https://github.com/purescript/purescript-strings/releases/tag/v0.7.0) - 2015-08-13 + +- Removed orphan (and incorrect) `Bounded Char` instance + +## [v0.6.0](https://github.com/purescript/purescript-strings/releases/tag/v0.6.0) - 2015-08-02 + +- Added `toLower` and `toUpper` to `Data.Char` +- `search` in `Data.String.Regex` now returns `Maybe` result rather than using -1 for failure +- Added test suite + +All updates by @LiamGoodacre + +## [v0.5.5](https://github.com/purescript/purescript-strings/releases/tag/v0.5.5) - 2015-07-28 + +Add `stripSuffix`. + +## [v0.5.4](https://github.com/purescript/purescript-strings/releases/tag/v0.5.4) - 2015-07-18 + +- Removed duplicate `Show` instance for `Char` (@anttih) + +## [v0.5.3](https://github.com/purescript/purescript-strings/releases/tag/v0.5.3) - 2015-07-10 + +Add `stripPrefix` (@hdgarrood) + +## [v0.5.2](https://github.com/purescript/purescript-strings/releases/tag/v0.5.2) - 2015-07-07 + +- Fixed `char` and `charCodeAt` in `Data.String.Unsafe` #36 (@stkb) + +## [v0.5.1](https://github.com/purescript/purescript-strings/releases/tag/v0.5.1) - 2015-07-06 + +- Fixed missing `count` implementation (@qxjit) + +## [v0.5.0](https://github.com/purescript/purescript-strings/releases/tag/v0.5.0) - 2015-06-30 + +This release works with versions 0.7.\* of the PureScript compiler. It will not work with older versions. If you are using an older version, you should require an older, compatible version of this library. + +## [v0.5.0-rc.3](https://github.com/purescript/purescript-strings/releases/tag/v0.5.0-rc.3) - 2015-06-12 + +- Fixed various FFI exports (@sharkdp) + +## [v0.5.0-rc.2](https://github.com/purescript/purescript-strings/releases/tag/v0.5.0-rc.2) - 2015-06-07 + +Fix `localeCompare` + +## [v0.5.0-rc.1](https://github.com/purescript/purescript-strings/releases/tag/v0.5.0-rc.1) - 2015-06-07 + +Initial release candidate of the library intended for the 0.7 compiler. + +## [v0.4.5](https://github.com/purescript/purescript-strings/releases/tag/v0.4.5) - 2015-03-23 + +- Added `char` to `Data.String.Unsafe` (@brainrape) +- Functions in `Data.String.Unsafe` now throw errors immediately when given unacceptable inputs (@brainrape) + +## [v0.4.4](https://github.com/purescript/purescript-strings/releases/tag/v0.4.4) - 2015-03-22 + +Updated docs + +## [v0.4.3](https://github.com/purescript/purescript-strings/releases/tag/v0.4.3) - 2015-02-18 + +- Added `noFlags` record for default regex flags (@fresheyeball) + +## [v0.4.2](https://github.com/purescript/purescript-strings/releases/tag/v0.4.2) - 2014-11-28 + + + +## [v0.4.1](https://github.com/purescript/purescript-strings/releases/tag/v0.4.1) - 2014-11-06 + + + +## [v0.4.0](https://github.com/purescript/purescript-strings/releases/tag/v0.4.0) - 2014-10-27 + +- Made `charCodeAt` safe, added unsafe versions of `charAt`, `charCodeAt` (@garyb) + +## [v0.3.3](https://github.com/purescript/purescript-strings/releases/tag/v0.3.3) - 2014-10-24 + +- Added `split` to `Data.String.Regex` (@davidchambers) + +## [v0.3.2](https://github.com/purescript/purescript-strings/releases/tag/v0.3.2) - 2014-10-16 + + + +## [v0.3.1](https://github.com/purescript/purescript-strings/releases/tag/v0.3.1) - 2014-10-15 + + + +## [v0.3.0](https://github.com/purescript/purescript-strings/releases/tag/v0.3.0) - 2014-10-14 + +- Introduced `Char` newtype and corresponding functions (@jdegoes) +- Made `charAt` safe - breaking change (@jdegoes) + +## [v0.2.1](https://github.com/purescript/purescript-strings/releases/tag/v0.2.1) - 2014-07-21 + +- Fix typo in FFI definition for `flags` (@garyb) + +## [v0.2.0](https://github.com/purescript/purescript-strings/releases/tag/v0.2.0) - 2014-07-20 + +- `Show` instance for `Regex` (@michaelficarra) +- `Regex` now has `RegexFlags` rather than a string for options (@michaelficarra) + +## [v0.1.3](https://github.com/purescript/purescript-strings/releases/tag/v0.1.3) - 2014-05-04 + +Renamed `Data.String.Regex.replaceR` to `replace`, added `replace'` which uses a function to construct replacements for matches. + +## [v0.1.2](https://github.com/purescript/purescript-strings/releases/tag/v0.1.2) - 2014-04-30 + +Added `indexOf'` and `lastIndexOf'` (paf31) + +## [v0.1.1](https://github.com/purescript/purescript-strings/releases/tag/v0.1.1) - 2014-04-27 + + + +## [v0.1.0](https://github.com/purescript/purescript-strings/releases/tag/v0.1.0) - 2014-04-25 + + + From dd35f96ca15bea479e130fda2a15a5b2d6b2575d Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Wed, 20 Jan 2021 04:00:38 -0800 Subject: [PATCH 13/26] Update changelog since v4.0.2 (#141) --- CHANGELOG.md | 64 +++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cf568f..0bacb51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,22 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] Breaking changes: +- Added support for PureScript 0.14 and dropped support for all previous versions (#129) +- Updated `replace'` to reflect the existence of optional capturing groups (#126) New features: +- Replaced `unsafeCoerce` with `coerce` where appropriate (#130) +- Replaced monomorphic proxies with `Type.Proxy.Proxy` and polymorphic variables (#134) +- Added a dotAll regexp flag (#133) Bugfixes: +- Removed the bounds check from the foreign implementation of `lastIndexOf'` (#137) Other improvements: +- Fix line endings to match overall project style (#132) +- Removed references to `codePointToInt`, which no longer exists (#135) +- Migrated CI to GitHub Actions and updated installation instructions to use Spago (#136) +- Added a changelog and pull request template (#140, #141) ## [v4.0.2](https://github.com/purescript/purescript-strings/releases/tag/v4.0.2) - 2020-05-13 @@ -37,22 +47,22 @@ Other improvements: ## [v3.4.0](https://github.com/purescript/purescript-strings/releases/tag/v3.4.0) - 2017-12-28 -* Add `Show CodePoint` instance (@csicar) -* Add `codePointFromChar` (@csicar) -* Expanded docs for most functions in `Data.String` and `Data.String.CodePoints` (@csicar) +- Add `Show CodePoint` instance (@csicar) +- Add `codePointFromChar` (@csicar) +- Expanded docs for most functions in `Data.String` and `Data.String.CodePoints` (@csicar) ## [v3.3.2](https://github.com/purescript/purescript-strings/releases/tag/v3.3.2) - 2017-11-19 -Performance improvement in `Data.String.Regex.match` (@fehrenbach) +- Performance improvement in `Data.String.Regex.match` (@fehrenbach) ## [v3.3.1](https://github.com/purescript/purescript-strings/releases/tag/v3.3.1) - 2017-08-06 -Fix some `Show` instances (@Rufflewind) +- Fix some `Show` instances (@Rufflewind) ## [v3.3.0](https://github.com/purescript/purescript-strings/releases/tag/v3.3.0) - 2017-07-10 -* Add a new module `Data.String.CodePoints`, which treats strings as sequences of Unicode code points rather than sequences of UTF-16 code units. In the future we may swap this module with `Data.String`. (@michaelficarra) -* Fix a typo in the documentation (@ijks) +- Add a new module `Data.String.CodePoints`, which treats strings as sequences of Unicode code points rather than sequences of UTF-16 code units. In the future we may swap this module with `Data.String`. (@michaelficarra) +- Fix a typo in the documentation (@ijks) ## [v3.2.1](https://github.com/purescript/purescript-strings/releases/tag/v3.2.1) - 2017-06-06 @@ -73,7 +83,7 @@ Fix some `Show` instances (@Rufflewind) ## [v2.1.0](https://github.com/purescript/purescript-strings/releases/tag/v2.1.0) - 2016-12-25 -Add `unsafeRegex` (@rightfold) +- Added `unsafeRegex` (@rightfold) ## [v2.0.2](https://github.com/purescript/purescript-strings/releases/tag/v2.0.2) - 2016-10-26 @@ -99,14 +109,6 @@ This release is intended for the PureScript 0.9.1 compiler and newer. **Note**: The v1.0.0 tag is not meant to indicate the library is “finished”, the core libraries are all being bumped to this for the 0.9 compiler release so as to use semver more correctly. -## [v1.0.0-rc.2](https://github.com/purescript/purescript-strings/releases/tag/v1.0.0-rc.2) - 2016-05-20 - -- Fix unused import warning - -## [v1.0.0-rc.1](https://github.com/purescript/purescript-strings/releases/tag/v1.0.0-rc.1) - 2016-03-24 - -- Release candidate for the psc 0.8+ core libraries - ## [v0.7.1](https://github.com/purescript/purescript-strings/releases/tag/v0.7.1) - 2015-11-20 - Removed unused imports (@tfausak) @@ -147,17 +149,8 @@ Add `stripPrefix` (@hdgarrood) This release works with versions 0.7.\* of the PureScript compiler. It will not work with older versions. If you are using an older version, you should require an older, compatible version of this library. -## [v0.5.0-rc.3](https://github.com/purescript/purescript-strings/releases/tag/v0.5.0-rc.3) - 2015-06-12 - - Fixed various FFI exports (@sharkdp) - -## [v0.5.0-rc.2](https://github.com/purescript/purescript-strings/releases/tag/v0.5.0-rc.2) - 2015-06-07 - -Fix `localeCompare` - -## [v0.5.0-rc.1](https://github.com/purescript/purescript-strings/releases/tag/v0.5.0-rc.1) - 2015-06-07 - -Initial release candidate of the library intended for the 0.7 compiler. +- Fixed `localeCompare` ## [v0.4.5](https://github.com/purescript/purescript-strings/releases/tag/v0.4.5) - 2015-03-23 @@ -166,7 +159,7 @@ Initial release candidate of the library intended for the 0.7 compiler. ## [v0.4.4](https://github.com/purescript/purescript-strings/releases/tag/v0.4.4) - 2015-03-22 -Updated docs +- Updated docs ## [v0.4.3](https://github.com/purescript/purescript-strings/releases/tag/v0.4.3) - 2015-02-18 @@ -174,11 +167,11 @@ Updated docs ## [v0.4.2](https://github.com/purescript/purescript-strings/releases/tag/v0.4.2) - 2014-11-28 - +- Added `null`, `singleton`, `uncons`, `takeWhile`, and `dropWhile` to `Data.String` (@NightRa) ## [v0.4.1](https://github.com/purescript/purescript-strings/releases/tag/v0.4.1) - 2014-11-06 - +- Use ternary operator in JavaScript output (@davidchambers) ## [v0.4.0](https://github.com/purescript/purescript-strings/releases/tag/v0.4.0) - 2014-10-27 @@ -190,11 +183,11 @@ Updated docs ## [v0.3.2](https://github.com/purescript/purescript-strings/releases/tag/v0.3.2) - 2014-10-16 - +- Added essential instances for `Char` (@jdegoes) ## [v0.3.1](https://github.com/purescript/purescript-strings/releases/tag/v0.3.1) - 2014-10-15 - +- Fixed typo in `fromCharArray` FFI implementation (@jdegoes) ## [v0.3.0](https://github.com/purescript/purescript-strings/releases/tag/v0.3.0) - 2014-10-14 @@ -212,17 +205,16 @@ Updated docs ## [v0.1.3](https://github.com/purescript/purescript-strings/releases/tag/v0.1.3) - 2014-05-04 -Renamed `Data.String.Regex.replaceR` to `replace`, added `replace'` which uses a function to construct replacements for matches. +- Renamed `Data.String.Regex.replaceR` to `replace`, added `replace'` which uses a function to construct replacements for matches. ## [v0.1.2](https://github.com/purescript/purescript-strings/releases/tag/v0.1.2) - 2014-04-30 -Added `indexOf'` and `lastIndexOf'` (paf31) +- Added `indexOf'` and `lastIndexOf'` (paf31) ## [v0.1.1](https://github.com/purescript/purescript-strings/releases/tag/v0.1.1) - 2014-04-27 - +- Swapped `joinWith` arguments for better style ## [v0.1.0](https://github.com/purescript/purescript-strings/releases/tag/v0.1.0) - 2014-04-25 - - +- Initial release From 157e372a23e4becd594d7e7bff6f372a6f63dd82 Mon Sep 17 00:00:00 2001 From: Cyril Date: Fri, 26 Feb 2021 19:55:44 +0100 Subject: [PATCH 14/26] Prepare v5.0.0 release (#144) * Update CI to build with the latest version of the compiler * Update the bower repository URL to match the URL in the registry * Upgrade bower dependencies * Update the changelog --- .github/workflows/ci.yml | 2 -- CHANGELOG.md | 10 ++++++++++ bower.json | 40 ++++++++++++++++++++-------------------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f4f44e5..43d2897 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,8 +13,6 @@ jobs: - uses: actions/checkout@v2 - uses: purescript-contrib/setup-purescript@main - with: - purescript: "0.14.0-rc5" - uses: actions/setup-node@v1 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bacb51..311b72b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] +Breaking changes: + +New features: + +Bugfixes: + +Other improvements: + +## [v5.0.0](https://github.com/purescript/purescript-strings/releases/tag/v5.0.0) - 2021-02-26 + Breaking changes: - Added support for PureScript 0.14 and dropped support for all previous versions (#129) - Updated `replace'` to reflect the existence of optional capturing groups (#126) diff --git a/bower.json b/bower.json index e401464..d4c9f36 100644 --- a/bower.json +++ b/bower.json @@ -4,7 +4,7 @@ "license": "BSD-3-Clause", "repository": { "type": "git", - "url": "git://github.com/purescript/purescript-strings.git" + "url": "https://github.com/purescript/purescript-strings.git" }, "ignore": [ "**/.*", @@ -16,26 +16,26 @@ "package.json" ], "dependencies": { - "purescript-arrays": "master", - "purescript-control": "master", - "purescript-either": "master", - "purescript-enums": "master", - "purescript-foldable-traversable": "master", - "purescript-gen": "master", - "purescript-integers": "master", - "purescript-maybe": "master", - "purescript-newtype": "master", - "purescript-nonempty": "master", - "purescript-partial": "master", - "purescript-prelude": "master", - "purescript-tailrec": "master", - "purescript-tuples": "master", - "purescript-unfoldable": "master", - "purescript-unsafe-coerce": "master" + "purescript-arrays": "^6.0.0", + "purescript-control": "^5.0.0", + "purescript-either": "^5.0.0", + "purescript-enums": "^5.0.0", + "purescript-foldable-traversable": "^5.0.0", + "purescript-gen": "^3.0.0", + "purescript-integers": "^5.0.0", + "purescript-maybe": "^5.0.0", + "purescript-newtype": "^4.0.0", + "purescript-nonempty": "^6.0.0", + "purescript-partial": "^3.0.0", + "purescript-prelude": "^5.0.0", + "purescript-tailrec": "^5.0.0", + "purescript-tuples": "^6.0.0", + "purescript-unfoldable": "^5.0.0", + "purescript-unsafe-coerce": "^5.0.0" }, "devDependencies": { - "purescript-assert": "master", - "purescript-console": "master", - "purescript-minibench": "master" + "purescript-assert": "^5.0.0", + "purescript-console": "^5.0.0", + "purescript-minibench": "^3.0.0" } } From 36493eee748bc35e2d4ecb09992f3c3eae42f4e8 Mon Sep 17 00:00:00 2001 From: Mohammed Anas <6daf084a-8eaf-40fb-86c7-8500077c3b69@anonaddy.me> Date: Thu, 22 Apr 2021 19:26:30 +0000 Subject: [PATCH 15/26] Use backticks around PS code in docs (#148) * Use backticks around PS code in docs * Add change to CHANGELOG.md --- CHANGELOG.md | 1 + src/Data/String/CodePoints.purs | 14 +++++++------- src/Data/String/CodeUnits.purs | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 311b72b..c3bf386 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ New features: Bugfixes: Other improvements: +- Surround code with backticks in documentation (#148) ## [v5.0.0](https://github.com/purescript/purescript-strings/releases/tag/v5.0.0) - 2021-02-26 diff --git a/src/Data/String/CodePoints.purs b/src/Data/String/CodePoints.purs index 7d0f528..65e0b55 100644 --- a/src/Data/String/CodePoints.purs +++ b/src/Data/String/CodePoints.purs @@ -42,7 +42,7 @@ import Data.String.Unsafe as Unsafe import Data.Tuple (Tuple(..)) import Data.Unfoldable (unfoldr) --- | CodePoint is an Int bounded between 0 and 0x10FFFF, corresponding to +-- | CodePoint is an `Int` bounded between `0` and `0x10FFFF`, corresponding to -- | Unicode code points. newtype CodePoint = CodePoint Int @@ -67,7 +67,7 @@ instance boundedEnumCodePoint :: BoundedEnum CodePoint where | n >= 0 && n <= 0x10FFFF = Just (CodePoint n) | otherwise = Nothing --- | Creates a CodePoint from a given Char. +-- | Creates a `CodePoint` from a given `Char`. -- | -- | ```purescript -- | >>> codePointFromChar 'B' @@ -178,7 +178,7 @@ codePointAtFallback n s = case uncons s of _ -> Nothing -- | Returns a record with the first code point and the remaining code points --- | of the string. Returns Nothing if the string is empty. Operates in +-- | of the string. Returns `Nothing` if the string is empty. Operates in -- | constant space and time. -- | -- | ```purescript @@ -243,7 +243,7 @@ countTail p s accum = case uncons s of _ -> accum -- | Returns the number of code points preceding the first match of the given --- | pattern in the string. Returns Nothing when no matches are found. +-- | pattern in the string. Returns `Nothing` when no matches are found. -- | -- | ```purescript -- | >>> indexOf (Pattern "𝐀") "b 𝐀𝐀 c 𝐀" @@ -257,7 +257,7 @@ indexOf p s = (\i -> length (CU.take i s)) <$> CU.indexOf p s -- | Returns the number of code points preceding the first match of the given -- | pattern in the string. Pattern matches preceding the given index will be --- | ignored. Returns Nothing when no matches are found. +-- | ignored. Returns `Nothing` when no matches are found. -- | -- | ```purescript -- | >>> indexOf' (Pattern "𝐀") 4 "b 𝐀𝐀 c 𝐀" @@ -272,7 +272,7 @@ indexOf' p i s = (\k -> i + length (CU.take k s')) <$> CU.indexOf p s' -- | Returns the number of code points preceding the last match of the given --- | pattern in the string. Returns Nothing when no matches are found. +-- | pattern in the string. Returns `Nothing` when no matches are found. -- | -- | ```purescript -- | >>> lastIndexOf (Pattern "𝐀") "b 𝐀𝐀 c 𝐀" @@ -292,7 +292,7 @@ lastIndexOf p s = (\i -> length (CU.take i s)) <$> CU.lastIndexOf p s -- | greater than the number of code points in the string is equivalent to -- | searching in the whole string. -- | --- | Returns Nothing when no matches are found. +-- | Returns `Nothing` when no matches are found. -- | -- | ```purescript -- | >>> lastIndexOf' (Pattern "𝐀") (-1) "b 𝐀𝐀 c 𝐀" diff --git a/src/Data/String/CodeUnits.purs b/src/Data/String/CodeUnits.purs index dfa0482..fbc1803 100644 --- a/src/Data/String/CodeUnits.purs +++ b/src/Data/String/CodeUnits.purs @@ -37,7 +37,7 @@ import Data.String.Unsafe as U ------------------------------------------------------------------------------- -- | If the string starts with the given prefix, return the portion of the --- | string left after removing it, as a Just value. Otherwise, return Nothing. +-- | string left after removing it, as a `Just` value. Otherwise, return `Nothing`. -- | -- | ```purescript -- | stripPrefix (Pattern "http:") "http://purescript.org" == Just "//purescript.org" From a8e757faa17ff24e6add938ba61a9375c867dd40 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Tue, 15 Mar 2022 13:18:54 -0700 Subject: [PATCH 16/26] Update to v0.15.0 (#158) * Convert foreign modules to try bundling with esbuild * Replaced 'export var' with 'export const' * Removed '"use strict";' in FFI files * Update to CI to use 'unstable' purescript * Update pulp to 16.0.0-0 and psa to 0.8.2 * Update Bower dependencies to master * Update .eslintrc.json to ES6 * Fix compiler error due to Proxy type * Fix unused name compiler warnings * Added changelog entry * Update test script to use import Co-authored-by: Cyril Sobierajewicz --- .eslintrc.json | 6 +-- .github/workflows/ci.yml | 2 + CHANGELOG.md | 2 + bower.json | 38 +++++++++---------- package.json | 6 +-- src/Data/String/CodePoints.js | 15 ++++---- src/Data/String/CodeUnits.js | 32 ++++++++-------- src/Data/String/Common.js | 18 ++++----- src/Data/String/NonEmpty/Internal.purs | 3 +- src/Data/String/Regex.js | 22 +++++------ src/Data/String/Unsafe.js | 6 +-- test/Test/Data/String/NonEmpty/CodeUnits.purs | 8 ++-- 12 files changed, 76 insertions(+), 82 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 84cef4f..1c6afb9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,11 +1,9 @@ { "parserOptions": { - "ecmaVersion": 5 + "ecmaVersion": 6, + "sourceType": "module" }, "extends": "eslint:recommended", - "env": { - "commonjs": true - }, "rules": { "strict": [2, "global"], "block-scoped-var": 2, diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43d2897..b6ebf3a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ jobs: - uses: actions/checkout@v2 - uses: purescript-contrib/setup-purescript@main + with: + purescript: "unstable" - uses: actions/setup-node@v1 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index c3bf386..d63cbd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] Breaking changes: +- Migrate FFI to ES modules (#158 by @kl0tl and @JordanMartinez) +- Replaced polymorphic proxies with monomorphic `Proxy` (#158 by @JordanMartinez) New features: diff --git a/bower.json b/bower.json index d4c9f36..2b8dd58 100644 --- a/bower.json +++ b/bower.json @@ -16,26 +16,26 @@ "package.json" ], "dependencies": { - "purescript-arrays": "^6.0.0", - "purescript-control": "^5.0.0", - "purescript-either": "^5.0.0", - "purescript-enums": "^5.0.0", - "purescript-foldable-traversable": "^5.0.0", - "purescript-gen": "^3.0.0", - "purescript-integers": "^5.0.0", - "purescript-maybe": "^5.0.0", - "purescript-newtype": "^4.0.0", - "purescript-nonempty": "^6.0.0", - "purescript-partial": "^3.0.0", - "purescript-prelude": "^5.0.0", - "purescript-tailrec": "^5.0.0", - "purescript-tuples": "^6.0.0", - "purescript-unfoldable": "^5.0.0", - "purescript-unsafe-coerce": "^5.0.0" + "purescript-arrays": "master", + "purescript-control": "master", + "purescript-either": "master", + "purescript-enums": "master", + "purescript-foldable-traversable": "master", + "purescript-gen": "master", + "purescript-integers": "master", + "purescript-maybe": "master", + "purescript-newtype": "master", + "purescript-nonempty": "master", + "purescript-partial": "master", + "purescript-prelude": "master", + "purescript-tailrec": "master", + "purescript-tuples": "master", + "purescript-unfoldable": "master", + "purescript-unsafe-coerce": "master" }, "devDependencies": { - "purescript-assert": "^5.0.0", - "purescript-console": "^5.0.0", - "purescript-minibench": "^3.0.0" + "purescript-assert": "master", + "purescript-console": "master", + "purescript-minibench": "master" } } diff --git a/package.json b/package.json index c116cae..cffd45e 100644 --- a/package.json +++ b/package.json @@ -4,15 +4,15 @@ "clean": "rimraf output && rimraf .pulp-cache", "build": "eslint src && pulp build -- --censor-lib --strict", "test": "pulp test && npm run test:run:without_codePointAt", - "test:run:without_codePointAt": "node -e \"delete String.prototype.codePointAt; require('./output/Test.Main/index.js').main();\"", + "test:run:without_codePointAt": "node -e \"delete String.prototype.codePointAt; import('./output/Test.Main/index.js').then(m => m.main());\"", "bench:build": "purs compile 'bench/**/*.purs' 'src/**/*.purs' 'bower_components/*/src/**/*.purs'", "bench:run": "node --expose-gc -e 'require(\"./output/Bench.Main/index.js\").main()'", "bench": "npm run bench:build && npm run bench:run" }, "devDependencies": { "eslint": "^7.15.0", - "pulp": "^15.0.0", - "purescript-psa": "^0.8.0", + "pulp": "16.0.0-0", + "purescript-psa": "^0.8.2", "rimraf": "^3.0.2" } } diff --git a/src/Data/String/CodePoints.js b/src/Data/String/CodePoints.js index eead7f6..ebd9e39 100644 --- a/src/Data/String/CodePoints.js +++ b/src/Data/String/CodePoints.js @@ -1,4 +1,3 @@ -"use strict"; /* global Symbol */ var hasArrayFrom = typeof Array.from === "function"; @@ -10,13 +9,13 @@ var hasStringIterator = var hasFromCodePoint = typeof String.prototype.fromCodePoint === "function"; var hasCodePointAt = typeof String.prototype.codePointAt === "function"; -exports._unsafeCodePointAt0 = function (fallback) { +export const _unsafeCodePointAt0 = function (fallback) { return hasCodePointAt ? function (str) { return str.codePointAt(0); } : fallback; }; -exports._codePointAt = function (fallback) { +export const _codePointAt = function (fallback) { return function (Just) { return function (Nothing) { return function (unsafeCodePointAt0) { @@ -40,7 +39,7 @@ exports._codePointAt = function (fallback) { }; }; -exports._countPrefix = function (fallback) { +export const _countPrefix = function (fallback) { return function (unsafeCodePointAt0) { if (hasStringIterator) { return function (pred) { @@ -59,7 +58,7 @@ exports._countPrefix = function (fallback) { }; }; -exports._fromCodePointArray = function (singleton) { +export const _fromCodePointArray = function (singleton) { return hasFromCodePoint ? function (cps) { // Function.prototype.apply will fail for very large second parameters, @@ -74,11 +73,11 @@ exports._fromCodePointArray = function (singleton) { }; }; -exports._singleton = function (fallback) { +export const _singleton = function (fallback) { return hasFromCodePoint ? String.fromCodePoint : fallback; }; -exports._take = function (fallback) { +export const _take = function (fallback) { return function (n) { if (hasStringIterator) { return function (str) { @@ -96,7 +95,7 @@ exports._take = function (fallback) { }; }; -exports._toCodePointArray = function (fallback) { +export const _toCodePointArray = function (fallback) { return function (unsafeCodePointAt0) { if (hasArrayFrom) { return function (str) { diff --git a/src/Data/String/CodeUnits.js b/src/Data/String/CodeUnits.js index 6017fd3..47d61f9 100644 --- a/src/Data/String/CodeUnits.js +++ b/src/Data/String/CodeUnits.js @@ -1,18 +1,16 @@ -"use strict"; - -exports.fromCharArray = function (a) { +export const fromCharArray = function (a) { return a.join(""); }; -exports.toCharArray = function (s) { +export const toCharArray = function (s) { return s.split(""); }; -exports.singleton = function (c) { +export const singleton = function (c) { return c; }; -exports._charAt = function (just) { +export const _charAt = function (just) { return function (nothing) { return function (i) { return function (s) { @@ -22,7 +20,7 @@ exports._charAt = function (just) { }; }; -exports._toChar = function (just) { +export const _toChar = function (just) { return function (nothing) { return function (s) { return s.length === 1 ? just(s) : nothing; @@ -30,11 +28,11 @@ exports._toChar = function (just) { }; }; -exports.length = function (s) { +export const length = function (s) { return s.length; }; -exports.countPrefix = function (p) { +export const countPrefix = function (p) { return function (s) { var i = 0; while (i < s.length && p(s.charAt(i))) i++; @@ -42,7 +40,7 @@ exports.countPrefix = function (p) { }; }; -exports._indexOf = function (just) { +export const _indexOf = function (just) { return function (nothing) { return function (x) { return function (s) { @@ -53,7 +51,7 @@ exports._indexOf = function (just) { }; }; -exports._indexOfStartingAt = function (just) { +export const _indexOfStartingAt = function (just) { return function (nothing) { return function (x) { return function (startAt) { @@ -67,7 +65,7 @@ exports._indexOfStartingAt = function (just) { }; }; -exports._lastIndexOf = function (just) { +export const _lastIndexOf = function (just) { return function (nothing) { return function (x) { return function (s) { @@ -78,7 +76,7 @@ exports._lastIndexOf = function (just) { }; }; -exports._lastIndexOfStartingAt = function (just) { +export const _lastIndexOfStartingAt = function (just) { return function (nothing) { return function (x) { return function (startAt) { @@ -91,19 +89,19 @@ exports._lastIndexOfStartingAt = function (just) { }; }; -exports.take = function (n) { +export const take = function (n) { return function (s) { return s.substr(0, n); }; }; -exports.drop = function (n) { +export const drop = function (n) { return function (s) { return s.substring(n); }; }; -exports._slice = function (b) { +export const _slice = function (b) { return function (e) { return function (s) { return s.slice(b,e); @@ -111,7 +109,7 @@ exports._slice = function (b) { }; }; -exports.splitAt = function (i) { +export const splitAt = function (i) { return function (s) { return { before: s.substring(0, i), after: s.substring(i) }; }; diff --git a/src/Data/String/Common.js b/src/Data/String/Common.js index 111c02e..5693585 100644 --- a/src/Data/String/Common.js +++ b/src/Data/String/Common.js @@ -1,6 +1,4 @@ -"use strict"; - -exports._localeCompare = function (lt) { +export const _localeCompare = function (lt) { return function (eq) { return function (gt) { return function (s1) { @@ -13,7 +11,7 @@ exports._localeCompare = function (lt) { }; }; -exports.replace = function (s1) { +export const replace = function (s1) { return function (s2) { return function (s3) { return s3.replace(s1, s2); @@ -21,7 +19,7 @@ exports.replace = function (s1) { }; }; -exports.replaceAll = function (s1) { +export const replaceAll = function (s1) { return function (s2) { return function (s3) { return s3.replace(new RegExp(s1.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"), "g"), s2); // eslint-disable-line no-useless-escape @@ -29,25 +27,25 @@ exports.replaceAll = function (s1) { }; }; -exports.split = function (sep) { +export const split = function (sep) { return function (s) { return s.split(sep); }; }; -exports.toLower = function (s) { +export const toLower = function (s) { return s.toLowerCase(); }; -exports.toUpper = function (s) { +export const toUpper = function (s) { return s.toUpperCase(); }; -exports.trim = function (s) { +export const trim = function (s) { return s.trim(); }; -exports.joinWith = function (s) { +export const joinWith = function (s) { return function (xs) { return xs.join(s); }; diff --git a/src/Data/String/NonEmpty/Internal.purs b/src/Data/String/NonEmpty/Internal.purs index 707b779..8722654 100644 --- a/src/Data/String/NonEmpty/Internal.purs +++ b/src/Data/String/NonEmpty/Internal.purs @@ -16,6 +16,7 @@ import Data.String as String import Data.String.Pattern (Pattern) import Data.Symbol (class IsSymbol, reflectSymbol) import Prim.TypeError as TE +import Type.Proxy (Proxy) import Unsafe.Coerce (unsafeCoerce) -- | A string that is known not to be empty. @@ -41,7 +42,7 @@ instance showNonEmptyString :: Show NonEmptyString where -- | something = nes (Proxy :: Proxy "something") -- | ``` class MakeNonEmpty (s :: Symbol) where - nes :: forall proxy. proxy s -> NonEmptyString + nes :: Proxy s -> NonEmptyString instance makeNonEmptyBad :: TE.Fail (TE.Text "Cannot create an NonEmptyString from an empty Symbol") => MakeNonEmpty "" where nes _ = NonEmptyString "" diff --git a/src/Data/String/Regex.js b/src/Data/String/Regex.js index b3be593..3196034 100644 --- a/src/Data/String/Regex.js +++ b/src/Data/String/Regex.js @@ -1,10 +1,8 @@ -"use strict"; - -exports.showRegexImpl = function (r) { +export const showRegexImpl = function (r) { return "" + r; }; -exports.regexImpl = function (left) { +export const regexImpl = function (left) { return function (right) { return function (s1) { return function (s2) { @@ -18,11 +16,11 @@ exports.regexImpl = function (left) { }; }; -exports.source = function (r) { +export const source = function (r) { return r.source; }; -exports.flagsImpl = function (r) { +export const flagsImpl = function (r) { return { multiline: r.multiline, ignoreCase: r.ignoreCase, @@ -33,7 +31,7 @@ exports.flagsImpl = function (r) { }; }; -exports.test = function (r) { +export const test = function (r) { return function (s) { var lastIndex = r.lastIndex; var result = r.test(s); @@ -42,7 +40,7 @@ exports.test = function (r) { }; }; -exports._match = function (just) { +export const _match = function (just) { return function (nothing) { return function (r) { return function (s) { @@ -60,7 +58,7 @@ exports._match = function (just) { }; }; -exports.replace = function (r) { +export const replace = function (r) { return function (s1) { return function (s2) { return s2.replace(r, s1); @@ -68,7 +66,7 @@ exports.replace = function (r) { }; }; -exports._replaceBy = function (just) { +export const _replaceBy = function (just) { return function (nothing) { return function (r) { return function (f) { @@ -87,7 +85,7 @@ exports._replaceBy = function (just) { }; }; -exports._search = function (just) { +export const _search = function (just) { return function (nothing) { return function (r) { return function (s) { @@ -98,7 +96,7 @@ exports._search = function (just) { }; }; -exports.split = function (r) { +export const split = function (r) { return function (s) { return s.split(r); }; diff --git a/src/Data/String/Unsafe.js b/src/Data/String/Unsafe.js index d7a17ca..75772aa 100644 --- a/src/Data/String/Unsafe.js +++ b/src/Data/String/Unsafe.js @@ -1,13 +1,11 @@ -"use strict"; - -exports.charAt = function (i) { +export const charAt = function (i) { return function (s) { if (i >= 0 && i < s.length) return s.charAt(i); throw new Error("Data.String.Unsafe.charAt: Invalid index."); }; }; -exports.char = function (s) { +export const char = function (s) { if (s.length === 1) return s.charAt(0); throw new Error("Data.String.Unsafe.char: Expected string of length 1."); }; diff --git a/test/Test/Data/String/NonEmpty/CodeUnits.purs b/test/Test/Data/String/NonEmpty/CodeUnits.purs index 9a33b0c..e810dd9 100644 --- a/test/Test/Data/String/NonEmpty/CodeUnits.purs +++ b/test/Test/Data/String/NonEmpty/CodeUnits.purs @@ -170,11 +170,11 @@ testNonEmptyStringCodeUnits = do log "takeWhile" assertEqual - { actual: NESCU.takeWhile (\c -> true) (nes (Proxy :: Proxy "abc")) + { actual: NESCU.takeWhile (\_ -> true) (nes (Proxy :: Proxy "abc")) , expected: Just (nes (Proxy :: Proxy "abc")) } assertEqual - { actual: NESCU.takeWhile (\c -> false) (nes (Proxy :: Proxy "abc")) + { actual: NESCU.takeWhile (\_ -> false) (nes (Proxy :: Proxy "abc")) , expected: Nothing } assertEqual @@ -192,11 +192,11 @@ testNonEmptyStringCodeUnits = do log "dropWhile" assertEqual - { actual: NESCU.dropWhile (\c -> true) (nes (Proxy :: Proxy "abc")) + { actual: NESCU.dropWhile (\_ -> true) (nes (Proxy :: Proxy "abc")) , expected: Nothing } assertEqual - { actual: NESCU.dropWhile (\c -> false) (nes (Proxy :: Proxy "abc")) + { actual: NESCU.dropWhile (\_ -> false) (nes (Proxy :: Proxy "abc")) , expected: Just (nes (Proxy :: Proxy "abc")) } assertEqual From d9ba5d0590de133d290f3a8ee12296d7bdea635b Mon Sep 17 00:00:00 2001 From: maynard Date: Fri, 25 Mar 2022 09:33:01 -0500 Subject: [PATCH 17/26] Relax Data.String.CodeUnits.slice bounds checking and drop Maybe in return type (#145) * For Data.String.CodeUnits.slice: remove bounds checking and drop `Maybe` in return type * Add changelog entry Co-authored-by: JordanMartinez --- CHANGELOG.md | 1 + src/Data/String/CodeUnits.js | 2 +- src/Data/String/CodeUnits.purs | 27 +++++++-------------------- test/Test/Data/String/CodeUnits.purs | 24 ++++++++++++++---------- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d63cbd2..02cb63e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based Breaking changes: - Migrate FFI to ES modules (#158 by @kl0tl and @JordanMartinez) - Replaced polymorphic proxies with monomorphic `Proxy` (#158 by @JordanMartinez) +- In `slice`, drop bounds checking and `Maybe` return type (#145 by Quelklef) New features: diff --git a/src/Data/String/CodeUnits.js b/src/Data/String/CodeUnits.js index 47d61f9..2608384 100644 --- a/src/Data/String/CodeUnits.js +++ b/src/Data/String/CodeUnits.js @@ -101,7 +101,7 @@ export const drop = function (n) { }; }; -export const _slice = function (b) { +export const slice = function (b) { return function (e) { return function (s) { return s.slice(b,e); diff --git a/src/Data/String/CodeUnits.purs b/src/Data/String/CodeUnits.purs index fbc1803..5fed21f 100644 --- a/src/Data/String/CodeUnits.purs +++ b/src/Data/String/CodeUnits.purs @@ -298,30 +298,17 @@ dropWhile p s = drop (countPrefix p s) s -- | Returns the substring at indices `[begin, end)`. -- | If either index is negative, it is normalised to `length s - index`, --- | where `s` is the input string. `Nothing` is returned if either +-- | where `s` is the input string. `""` is returned if either -- | index is out of bounds or if `begin > end` after normalisation. -- | -- | ```purescript --- | slice 0 0 "purescript" == Just "" --- | slice 0 1 "purescript" == Just "p" --- | slice 3 6 "purescript" == Just "esc" --- | slice (-4) (-1) "purescript" == Just "rip" --- | slice (-4) 3 "purescript" == Nothing +-- | slice 0 0 "purescript" == "" +-- | slice 0 1 "purescript" == "p" +-- | slice 3 6 "purescript" == "esc" +-- | slice (-4) (-1) "purescript" == "rip" +-- | slice (-4) 3 "purescript" == "" -- | ``` -slice :: Int -> Int -> String -> Maybe String -slice b e s = if b' < 0 || b' >= l || - e' < 0 || e' > l || - b' > e' - then Nothing - else Just (_slice b e s) - where - l = length s - norm x | x < 0 = l + x - | otherwise = x - b' = norm b - e' = norm e - -foreign import _slice :: Int -> Int -> String -> String +foreign import slice :: Int -> Int -> String -> String -- | Splits a string into two substrings, where `before` contains the -- | characters up to (but not including) the given index, and `after` contains diff --git a/test/Test/Data/String/CodeUnits.purs b/test/Test/Data/String/CodeUnits.purs index 9cf010b..ddd512b 100644 --- a/test/Test/Data/String/CodeUnits.purs +++ b/test/Test/Data/String/CodeUnits.purs @@ -472,41 +472,45 @@ testStringCodeUnits = do log "slice" assertEqual { actual: SCU.slice 0 0 "purescript" - , expected: Just "" + , expected: "" } assertEqual { actual: SCU.slice 0 1 "purescript" - , expected: Just "p" + , expected: "p" } assertEqual { actual: SCU.slice 3 6 "purescript" - , expected: Just "esc" + , expected: "esc" } assertEqual { actual: SCU.slice 3 10 "purescript" - , expected: Just "escript" + , expected: "escript" + } + assertEqual + { actual: SCU.slice 10 10 "purescript" + , expected: "" } assertEqual { actual: SCU.slice (-4) (-1) "purescript" - , expected: Just "rip" + , expected: "rip" } assertEqual { actual: SCU.slice (-4) 3 "purescript" - , expected: Nothing -- b' > e' + , expected: "" } assertEqual { actual: SCU.slice 1000 3 "purescript" - , expected: Nothing -- b' > e' (subsumes b > l) + , expected: "" } assertEqual { actual: SCU.slice 2 (-15) "purescript" - , expected: Nothing -- e' < 0 + , expected: "" } assertEqual { actual: SCU.slice (-15) 9 "purescript" - , expected: Nothing -- b' < 0 + , expected: "purescrip" } assertEqual { actual: SCU.slice 3 1000 "purescript" - , expected: Nothing -- e > l + , expected: "escript" } From bd172f8bf87d31315a9b4462b0522db2144414c9 Mon Sep 17 00:00:00 2001 From: Mohammed Anas <6daf084a-8eaf-40fb-86c7-8500077c3b69@anonaddy.me> Date: Sun, 17 Apr 2022 13:25:57 +0000 Subject: [PATCH 18/26] Fix formatting (#160) --- src/Data/String/Regex/Flags.purs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Data/String/Regex/Flags.purs b/src/Data/String/Regex/Flags.purs index dc7a0c7..822f8d1 100644 --- a/src/Data/String/Regex/Flags.purs +++ b/src/Data/String/Regex/Flags.purs @@ -23,7 +23,7 @@ noFlags = RegexFlags { global: false , ignoreCase: false , multiline: false - , dotAll : false + , dotAll: false , sticky: false , unicode: false } @@ -34,7 +34,7 @@ global = RegexFlags { global: true , ignoreCase: false , multiline: false - , dotAll : false + , dotAll: false , sticky: false , unicode: false } @@ -45,7 +45,7 @@ ignoreCase = RegexFlags { global: false , ignoreCase: true , multiline: false - , dotAll : false + , dotAll: false , sticky: false , unicode: false } @@ -56,7 +56,7 @@ multiline = RegexFlags { global: false , ignoreCase: false , multiline: true - , dotAll : false + , dotAll: false , sticky: false , unicode: false } @@ -67,7 +67,7 @@ sticky = RegexFlags { global: false , ignoreCase: false , multiline: false - , dotAll : false + , dotAll: false , sticky: true , unicode: false } @@ -78,7 +78,7 @@ unicode = RegexFlags { global: false , ignoreCase: false , multiline: false - , dotAll : false + , dotAll: false , sticky: false , unicode: true } @@ -89,7 +89,7 @@ dotAll = RegexFlags { global: false , ignoreCase: false , multiline: false - , dotAll : true + , dotAll: true , sticky: false , unicode: false } From b2565978793ecd5ad6a460009ae8d5ea5c3b9c20 Mon Sep 17 00:00:00 2001 From: Mohammed Anas <6daf084a-8eaf-40fb-86c7-8500077c3b69@anonaddy.me> Date: Sun, 17 Apr 2022 13:26:44 +0000 Subject: [PATCH 19/26] Make `RegexFlags` a `newtype` (#159) --- CHANGELOG.md | 1 + src/Data/String/Regex/Flags.purs | 14 +++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02cb63e..28863e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Bugfixes: Other improvements: - Surround code with backticks in documentation (#148) +- Make `RegexFlags` a `newtype` and a `Newtype` instance for it(#159 by @mhmdanas) ## [v5.0.0](https://github.com/purescript/purescript-strings/releases/tag/v5.0.0) - 2021-02-26 diff --git a/src/Data/String/Regex/Flags.purs b/src/Data/String/Regex/Flags.purs index 822f8d1..6d7dd71 100644 --- a/src/Data/String/Regex/Flags.purs +++ b/src/Data/String/Regex/Flags.purs @@ -3,6 +3,7 @@ module Data.String.Regex.Flags where import Prelude import Control.MonadPlus (guard) +import Data.Newtype (class Newtype) import Data.String (joinWith) type RegexFlagsRec = @@ -15,7 +16,9 @@ type RegexFlagsRec = } -- | Flags that control matching. -data RegexFlags = RegexFlags RegexFlagsRec +newtype RegexFlags = RegexFlags RegexFlagsRec + +derive instance newtypeRegexFlags :: Newtype RegexFlags _ -- | All flags set to false. noFlags :: RegexFlags @@ -107,14 +110,7 @@ instance semigroupRegexFlags :: Semigroup RegexFlags where instance monoidRegexFlags :: Monoid RegexFlags where mempty = noFlags -instance eqRegexFlags :: Eq RegexFlags where - eq (RegexFlags x) (RegexFlags y) - = x.global == y.global - && x.ignoreCase == y.ignoreCase - && x.multiline == y.multiline - && x.dotAll == y.dotAll - && x.sticky == y.sticky - && x.unicode == y.unicode +derive newtype instance eqRegexFlags :: Eq RegexFlags instance showRegexFlags :: Show RegexFlags where show (RegexFlags flags) = From 4bc6954448d056f8aa7a659695a6ad60ad4fdf19 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Wed, 27 Apr 2022 16:24:51 -0500 Subject: [PATCH 20/26] Prepare v6.0.0 release (1st PS 0.15.0-compatible release) (#161) * Update the bower dependencies * Update Node to 14 in CI * Update the changelog --- .github/workflows/ci.yml | 4 ++-- CHANGELOG.md | 10 ++++++++++ bower.json | 38 +++++++++++++++++++------------------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6ebf3a..c69237a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,9 +16,9 @@ jobs: with: purescript: "unstable" - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: - node-version: "12" + node-version: "14.x" - name: Install dependencies run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 28863e1..52a8669 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] +Breaking changes: + +New features: + +Bugfixes: + +Other improvements: + +## [v6.0.0](https://github.com/purescript/purescript-strings/releases/tag/v6.0.0) - 2022-04-27 + Breaking changes: - Migrate FFI to ES modules (#158 by @kl0tl and @JordanMartinez) - Replaced polymorphic proxies with monomorphic `Proxy` (#158 by @JordanMartinez) diff --git a/bower.json b/bower.json index 2b8dd58..cceeac4 100644 --- a/bower.json +++ b/bower.json @@ -16,26 +16,26 @@ "package.json" ], "dependencies": { - "purescript-arrays": "master", - "purescript-control": "master", - "purescript-either": "master", - "purescript-enums": "master", - "purescript-foldable-traversable": "master", - "purescript-gen": "master", - "purescript-integers": "master", - "purescript-maybe": "master", - "purescript-newtype": "master", - "purescript-nonempty": "master", - "purescript-partial": "master", - "purescript-prelude": "master", - "purescript-tailrec": "master", - "purescript-tuples": "master", - "purescript-unfoldable": "master", - "purescript-unsafe-coerce": "master" + "purescript-arrays": "^7.0.0", + "purescript-control": "^6.0.0", + "purescript-either": "^6.0.0", + "purescript-enums": "^6.0.0", + "purescript-foldable-traversable": "^6.0.0", + "purescript-gen": "^4.0.0", + "purescript-integers": "^6.0.0", + "purescript-maybe": "^6.0.0", + "purescript-newtype": "^5.0.0", + "purescript-nonempty": "^7.0.0", + "purescript-partial": "^4.0.0", + "purescript-prelude": "^6.0.0", + "purescript-tailrec": "^6.0.0", + "purescript-tuples": "^7.0.0", + "purescript-unfoldable": "^6.0.0", + "purescript-unsafe-coerce": "^6.0.0" }, "devDependencies": { - "purescript-assert": "master", - "purescript-console": "master", - "purescript-minibench": "master" + "purescript-assert": "^6.0.0", + "purescript-console": "^6.0.0", + "purescript-minibench": "^4.0.0" } } From abded947c3270cc102172b6e0302bc8f4ad86f22 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Tue, 16 Aug 2022 17:27:30 -0500 Subject: [PATCH 21/26] Use fixed Char enums version (#163) * Use fixed Char enums version * Add changelog entry --- CHANGELOG.md | 1 + bower.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52a8669..1fdc6e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Breaking changes: New features: Bugfixes: +- Fix `Char`'s `toEnum` implementation (#163 by @JordanMartinez) Other improvements: diff --git a/bower.json b/bower.json index cceeac4..85a17c5 100644 --- a/bower.json +++ b/bower.json @@ -19,7 +19,7 @@ "purescript-arrays": "^7.0.0", "purescript-control": "^6.0.0", "purescript-either": "^6.0.0", - "purescript-enums": "^6.0.0", + "purescript-enums": "^6.0.1", "purescript-foldable-traversable": "^6.0.0", "purescript-gen": "^4.0.0", "purescript-integers": "^6.0.0", From 82c2c9a6e3bb189902357faa9396f52a5f79fa36 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 16 Aug 2022 17:30:01 -0500 Subject: [PATCH 22/26] Prep changelog for v6.0.1 --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fdc6e7..f36a713 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,14 @@ Breaking changes: New features: Bugfixes: -- Fix `Char`'s `toEnum` implementation (#163 by @JordanMartinez) Other improvements: +## [v6.0.1](https://github.com/purescript/purescript-strings/releases/tag/v6.0.1) - 2022-08-16 + +Bugfixes: +- Fix `Char`'s `toEnum` implementation (#163 by @JordanMartinez) + ## [v6.0.0](https://github.com/purescript/purescript-strings/releases/tag/v6.0.0) - 2022-04-27 Breaking changes: From 3d3e2f7197d4f7aacb15e854ee9a645489555fff Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 16 Aug 2022 17:31:08 -0500 Subject: [PATCH 23/26] v6.0.1 From 373c44a8f0ac776be836cc2d0f3b6a70a5525b07 Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Mon, 30 Oct 2023 18:50:37 +0200 Subject: [PATCH 24/26] Better definition for `Data.String.NonEmpty.CodeUnits.fromFoldable1` (#168) --- CHANGELOG.md | 5 +++++ src/Data/String/NonEmpty/CodeUnits.purs | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f36a713..c0def5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ Bugfixes: Other improvements: +## [v6.0.2] + +Other improvements: +- Redefine `Data.String.NonEmpty.CodeUnits.fromFoldable1` in terms of `singleton` (#168 by @postsolar) + ## [v6.0.1](https://github.com/purescript/purescript-strings/releases/tag/v6.0.1) - 2022-08-16 Bugfixes: diff --git a/src/Data/String/NonEmpty/CodeUnits.purs b/src/Data/String/NonEmpty/CodeUnits.purs index af3de43..4e97244 100644 --- a/src/Data/String/NonEmpty/CodeUnits.purs +++ b/src/Data/String/NonEmpty/CodeUnits.purs @@ -37,7 +37,6 @@ import Data.String.NonEmpty.Internal (NonEmptyString(..), fromString) import Data.String.Pattern (Pattern) import Data.String.Unsafe as U import Partial.Unsafe (unsafePartial) -import Unsafe.Coerce (unsafeCoerce) -- For internal use only. Do not export. toNonEmptyString :: String -> NonEmptyString @@ -91,10 +90,7 @@ snoc c s = toNonEmptyString (s <> CU.singleton c) -- | Creates a `NonEmptyString` from a `Foldable1` container carrying -- | characters. fromFoldable1 :: forall f. Foldable1 f => f Char -> NonEmptyString -fromFoldable1 = F1.fold1 <<< coe - where - coe ∷ f Char -> f NonEmptyString - coe = unsafeCoerce +fromFoldable1 = F1.foldMap1 singleton -- | Converts the `NonEmptyString` into an array of characters. -- | From 72bb066aaf9f6f8ab049300bdd0ff8e90e21711d Mon Sep 17 00:00:00 2001 From: Nathan Faubion Date: Mon, 30 Oct 2023 09:52:04 -0700 Subject: [PATCH 25/26] Update CHANGELOG.md Fixup bad changelog entry. --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0def5e..878d55d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,6 @@ New features: Bugfixes: -Other improvements: - -## [v6.0.2] - Other improvements: - Redefine `Data.String.NonEmpty.CodeUnits.fromFoldable1` in terms of `singleton` (#168 by @postsolar) From b6654d49e2300416b25c05a00a0e6065c29fcf07 Mon Sep 17 00:00:00 2001 From: Nicholas Wolverson Date: Thu, 26 Dec 2024 12:18:56 +0000 Subject: [PATCH 26/26] Update take docstring to match the behaviour (#172) --- src/Data/String/CodePoints.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/String/CodePoints.purs b/src/Data/String/CodePoints.purs index 65e0b55..610e497 100644 --- a/src/Data/String/CodePoints.purs +++ b/src/Data/String/CodePoints.purs @@ -314,7 +314,7 @@ lastIndexOf' p i s = -- | Returns a string containing the given number of code points from the -- | beginning of the given string. If the string does not have that many code --- | points, returns the empty string. Operates in constant space and in time +-- | points, returns the entire string. Operates in constant space and in time -- | linear to the given number. -- | -- | ```purescript