Skip to content

Commit dc3e3de

Browse files
committed
Updates for 0.7
1 parent 6d66332 commit dc3e3de

File tree

8 files changed

+267
-294
lines changed

8 files changed

+267
-294
lines changed

src/Data/Char.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* global exports */
2+
"use strict";
3+
4+
// module Data.Char
5+
6+
exports.toString = function(c) {
7+
return c;
8+
};
9+
10+
exports.toCharCode = function(c) {
11+
return c.charCodeAt(0);
12+
};
13+
14+
exports.fromCharCode = function(c) {
15+
return String.fromCharCode(c);
16+
};

src/Data/Char.purs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,28 @@
11
-- | A type and functions for single characters.
22
module Data.Char
3-
( Char()
4-
, toString
3+
( toString
54
, fromCharCode
65
, toCharCode
76
) where
87

9-
import Data.Int (Int(), fromNumber)
8+
import Prelude
109

11-
--| A unicode character.
12-
newtype Char = Char String
10+
import Data.Int (fromNumber)
1311

1412
-- | Returns the string of length `1` containing only the given character.
15-
toString :: Char -> String
16-
toString (Char s) = s
13+
foreign import toString :: Char -> String
1714

1815
-- | Returns the numeric Unicode value of the character.
19-
foreign import toCharCode
20-
"""
21-
function toCharCode(c) {
22-
return c.charCodeAt(0);
23-
}
24-
""" :: Char -> Int
16+
foreign import toCharCode :: Char -> Int
2517

2618
-- | Constructs a character from the given Unicode numeric value.
27-
foreign import fromCharCode
28-
"""
29-
function fromCharCode(c) {
30-
return String.fromCharCode(c);
31-
}
32-
""" :: Int -> Char
33-
34-
-- | Characters can be compared for equality with `==` and `/=`.
35-
instance eqChar :: Eq Char where
36-
(==) (Char a) (Char b) = a == b
37-
(/=) a b = not (a == b)
38-
39-
-- | Characters can be compared with `compare`, `>`, `>=`, `<` and `<=`.
40-
instance ordChar :: Ord Char where
41-
compare (Char a) (Char b) = a `compare` b
19+
foreign import fromCharCode :: Int -> Char
4220

4321
-- | Characters fall within the Unicode range.
4422
instance boundedChar :: Bounded Char where
4523
top = fromCharCode zero
46-
bottom = fromCharCode (fromNumber 65535)
24+
bottom = fromCharCode 65535
4725

4826
-- | Characters can be rendered as a string with `show`.
4927
instance showChar :: Show Char where
50-
show (Char s) = "Char " ++ show s
28+
show c = "Char " ++ show (toString c)

src/Data/String.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/* global exports */
2+
"use strict";
3+
4+
// module Data.String
5+
6+
exports._charAt = function(i, s, Just, Nothing) {
7+
return i >= 0 && i < s.length ? Just(s.charAt(i)) : Nothing;
8+
};
9+
10+
exports._charCodeAt = function(i, s, Just, Nothing) {
11+
return i >= 0 && i < s.length ? Just(s.charCodeAt(i)) : Nothing;
12+
};
13+
14+
exports.fromCharArray = function(a) {
15+
return a.join('');
16+
};
17+
18+
exports._indexOf = function(just, nothing, x, s) {
19+
var i = s.indexOf(x);
20+
return i == -1 ? nothing : just(i);
21+
};
22+
23+
exports._indexOf$prime = function(just, nothing, x, startAt, s) {
24+
var i = s.indexOf(x, startAt);
25+
return i == -1 ? nothing : just(i);
26+
};
27+
28+
exports._lastIndexOf = function(just, nothing, x, s) {
29+
var i = s.lastIndexOf(x);
30+
return i == -1 ? nothing : just(i);
31+
};
32+
33+
exports._lastIndexOf$prime = function(just, nothing, x, startAt, s) {
34+
var i = s.lastIndexOf(x, startAt);
35+
return i == -1 ? nothing : just(i);
36+
};
37+
38+
exports.length = function(s) {
39+
return s.length;
40+
};
41+
42+
exports.localeCompare = function(lt, eq, gt, s1, s2) {
43+
var result = s1.localeCompare(s2);
44+
return result < 0 ? lt : result > 1 ? gt : eq;
45+
};
46+
47+
exports.replace = function(s1) {
48+
return function(s2) {
49+
return function(s3) {
50+
return s3.replace(s1, s2);
51+
};
52+
};
53+
};
54+
55+
exports.take = function(n) {
56+
return function(s) {
57+
return s.substr(0, n);
58+
};
59+
};
60+
61+
exports.drop = function(n) {
62+
return function(s) {
63+
return s.substr(n);
64+
};
65+
};
66+
67+
exports.split = function(sep) {
68+
return function(s) {
69+
return s.split(sep);
70+
};
71+
};
72+
73+
exports.toCharArray = function(s) {
74+
return s.split('');
75+
};
76+
77+
exports.toLower = function(s) {
78+
return s.toLowerCase();
79+
};
80+
81+
exports.toUpper = function(s) {
82+
return s.toUpperCase();
83+
};
84+
85+
exports.trim = function(s) {
86+
return s.trim();
87+
};
88+
89+
exports.joinWith = function(s) {
90+
return function(xs) {
91+
return xs.join(s);
92+
};
93+
};

0 commit comments

Comments
 (0)