Skip to content

Commit d723c30

Browse files
committed
Major re-arrange for CodeUnit/CodePoint split
1 parent e019df0 commit d723c30

27 files changed

+2948
-1494
lines changed

bower.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20+
"purescript-arrays": "#compiler/0.12",
2021
"purescript-either": "#compiler/0.12",
22+
"purescript-enums": "#compiler/0.12",
2123
"purescript-gen": "#compiler/0.12",
24+
"purescript-integers": "#compiler/0.12",
2225
"purescript-maybe": "#compiler/0.12",
2326
"purescript-partial": "#compiler/0.12",
24-
"purescript-unfoldable": "#compiler/0.12",
25-
"purescript-arrays": "#compiler/0.12",
26-
"purescript-integers": "#compiler/0.12"
27+
"purescript-unfoldable": "#compiler/0.12"
2728
},
2829
"devDependencies": {
2930
"purescript-assert": "#compiler/0.12",

src/Data/Char.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
"use strict";
22

3-
exports.toCharCode = function (c) {
4-
return c.charCodeAt(0);
5-
};
6-
7-
exports.fromCharCode = function (c) {
8-
return String.fromCharCode(c);
9-
};
10-
113
exports.toLower = function (c) {
124
return c.toLowerCase();
135
};

src/Data/Char.purs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
-- | A type and functions for single characters.
22
module Data.Char
3-
( fromCharCode
4-
, toCharCode
5-
, toLower
3+
( toLower
64
, toUpper
75
) where
86

9-
-- | Returns the numeric Unicode value of the character.
10-
foreign import toCharCode :: Char -> Int
11-
12-
-- | Constructs a character from the given Unicode numeric value.
13-
foreign import fromCharCode :: Int -> Char
14-
157
-- | Converts a character to lowercase.
168
foreign import toLower :: Char -> Char
179

src/Data/Char/Gen.purs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ module Data.Char.Gen where
33
import Prelude
44

55
import Control.Monad.Gen (class MonadGen, chooseInt, oneOf)
6-
import Data.Char as C
6+
import Data.Enum (toEnumWithDefaults)
77
import Data.NonEmpty ((:|))
88

99
-- | Generates a character of the Unicode basic multilingual plane.
1010
genUnicodeChar :: forall m. MonadGen m => m Char
11-
genUnicodeChar = C.fromCharCode <$> chooseInt 0 65536
11+
genUnicodeChar = toEnumWithDefaults bottom top <$> chooseInt 0 65536
1212

1313
-- | Generates a character in the ASCII character set, excluding control codes.
1414
genAsciiChar :: forall m. MonadGen m => m Char
15-
genAsciiChar = C.fromCharCode <$> chooseInt 32 127
15+
genAsciiChar = toEnumWithDefaults bottom top <$> chooseInt 32 127
1616

1717
-- | Generates a character in the ASCII character set.
1818
genAsciiChar' :: forall m. MonadGen m => m Char
19-
genAsciiChar' = C.fromCharCode <$> chooseInt 0 127
19+
genAsciiChar' = toEnumWithDefaults bottom top <$> chooseInt 0 127
2020

2121
-- | Generates a character that is a numeric digit.
2222
genDigitChar :: forall m. MonadGen m => m Char
23-
genDigitChar = C.fromCharCode <$> chooseInt 48 57
23+
genDigitChar = toEnumWithDefaults bottom top <$> chooseInt 48 57
2424

2525
-- | Generates a character from the basic latin alphabet.
2626
genAlpha :: forall m. MonadGen m => m Char
2727
genAlpha = oneOf (genAlphaLowercase :| [genAlphaUppercase])
2828

2929
-- | Generates a lowercase character from the basic latin alphabet.
3030
genAlphaLowercase :: forall m. MonadGen m => m Char
31-
genAlphaLowercase = C.fromCharCode <$> chooseInt 97 122
31+
genAlphaLowercase = toEnumWithDefaults bottom top <$> chooseInt 97 122
3232

3333
-- | Generates an uppercase character from the basic latin alphabet.
3434
genAlphaUppercase :: forall m. MonadGen m => m Char
35-
genAlphaUppercase = C.fromCharCode <$> chooseInt 65 90
35+
genAlphaUppercase = toEnumWithDefaults bottom top <$> chooseInt 65 90

src/Data/String.purs

Lines changed: 4 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,9 @@
1-
-- | Wraps the functions of Javascript's `String` object.
2-
-- | A String represents a sequence of characters.
3-
-- | For details of the underlying implementation, see [String Reference at MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String).
41
module Data.String
52
( module Data.String.Pattern
6-
, contains
7-
, null
8-
, localeCompare
9-
, replace
10-
, replaceAll
11-
, stripPrefix
12-
, stripSuffix
13-
, split
14-
, toLower
15-
, toUpper
16-
, trim
17-
, joinWith
3+
, module Data.String.Common
4+
, module Data.String.CodeUnits
185
) where
196

20-
import Prelude
21-
22-
import Data.Maybe (Maybe(..), isJust)
23-
import Data.String.CodeUnits as SCU
247
import Data.String.Pattern (Pattern(..), Replacement(..))
25-
26-
-- | Returns `true` if the given string is empty.
27-
-- |
28-
-- | ```purescript
29-
-- | null "" == true
30-
-- | null "Hi" == false
31-
-- | ```
32-
null :: String -> Boolean
33-
null s = s == ""
34-
35-
-- | If the string starts with the given prefix, return the portion of the
36-
-- | string left after removing it, as a Just value. Otherwise, return Nothing.
37-
-- |
38-
-- | ```purescript
39-
-- | stripPrefix (Pattern "http:") "http://purescript.org" == Just "//purescript.org"
40-
-- | stripPrefix (Pattern "http:") "https://purescript.org" == Nothing
41-
-- | ```
42-
stripPrefix :: Pattern -> String -> Maybe String
43-
stripPrefix prefix@(Pattern prefixS) str =
44-
case SCU.indexOf prefix str of
45-
Just 0 -> Just $ SCU.drop (SCU.length prefixS) str
46-
_ -> Nothing
47-
48-
-- | If the string ends with the given suffix, return the portion of the
49-
-- | string left after removing it, as a `Just` value. Otherwise, return
50-
-- | `Nothing`.
51-
-- |
52-
-- | ```purescript
53-
-- | stripSuffix (Pattern ".exe") "psc.exe" == Just "psc"
54-
-- | stripSuffix (Pattern ".exe") "psc" == Nothing
55-
-- | ```
56-
stripSuffix :: Pattern -> String -> Maybe String
57-
stripSuffix suffix@(Pattern suffixS) str =
58-
case SCU.lastIndexOf suffix str of
59-
Just x | x == SCU.length str - SCU.length suffixS -> Just $ SCU.take x str
60-
_ -> Nothing
61-
62-
-- | Checks whether the pattern appears in the given string.
63-
-- |
64-
-- | ```purescript
65-
-- | contains (Pattern "needle") "haystack with needle" == true
66-
-- | contains (Pattern "needle") "haystack" == false
67-
-- | ```
68-
contains :: Pattern -> String -> Boolean
69-
contains pat = isJust <<< SCU.indexOf pat
70-
71-
-- | Compare two strings in a locale-aware fashion. This is in contrast to
72-
-- | the `Ord` instance on `String` which treats strings as arrays of code
73-
-- | units:
74-
-- |
75-
-- | ```purescript
76-
-- | "ä" `localeCompare` "b" == LT
77-
-- | "ä" `compare` "b" == GT
78-
-- | ```
79-
localeCompare :: String -> String -> Ordering
80-
localeCompare = _localeCompare LT EQ GT
81-
82-
foreign import _localeCompare
83-
:: Ordering
84-
-> Ordering
85-
-> Ordering
86-
-> String
87-
-> String
88-
-> Ordering
89-
90-
-- | Replaces the first occurence of the pattern with the replacement string.
91-
-- |
92-
-- | ```purescript
93-
-- | replace (Pattern "<=") (Replacement "≤") "a <= b <= c" == "a ≤ b <= c"
94-
-- | ```
95-
foreign import replace :: Pattern -> Replacement -> String -> String
96-
97-
-- | Replaces all occurences of the pattern with the replacement string.
98-
-- |
99-
-- | ```purescript
100-
-- | replaceAll (Pattern "<=") (Replacement "≤") "a <= b <= c" == "a ≤ b ≤ c"
101-
-- | ```
102-
foreign import replaceAll :: Pattern -> Replacement -> String -> String
103-
104-
-- | Returns the substrings of the second string separated along occurences
105-
-- | of the first string.
106-
-- |
107-
-- | ```purescript
108-
-- | split (Pattern " ") "hello world" == ["hello", "world"]
109-
-- | ```
110-
foreign import split :: Pattern -> String -> Array String
111-
112-
-- | Returns the argument converted to lowercase.
113-
-- |
114-
-- | ```purescript
115-
-- | toLower "hElLo" == "hello"
116-
-- | ```
117-
foreign import toLower :: String -> String
118-
119-
-- | Returns the argument converted to uppercase.
120-
-- |
121-
-- | ```purescript
122-
-- | toUpper "Hello" == "HELLO"
123-
-- | ```
124-
foreign import toUpper :: String -> String
125-
126-
-- | Removes whitespace from the beginning and end of a string, including
127-
-- | [whitespace characters](http://www.ecma-international.org/ecma-262/5.1/#sec-7.2)
128-
-- | and [line terminators](http://www.ecma-international.org/ecma-262/5.1/#sec-7.3).
129-
-- |
130-
-- | ```purescript
131-
-- | trim " Hello \n World\n\t " == "Hello \n World"
132-
-- | ```
133-
foreign import trim :: String -> String
134-
135-
-- | Joins the strings in the array together, inserting the first argument
136-
-- | as separator between them.
137-
-- |
138-
-- | ```purescript
139-
-- | joinWith ", " ["apple", "banana", "orange"] == "apple, banana, orange"
140-
-- | ```
141-
foreign import joinWith :: String -> Array String -> String
8+
import Data.String.Common (joinWith, localeCompare, null, replace, replaceAll, split, toLower, toUpper, trim)
9+
import Data.String.CodeUnits (contains, stripPrefix, stripSuffix)
File renamed without changes.

0 commit comments

Comments
 (0)