Skip to content

use triple-quoted strings to avoid backslashes #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/Data/Char/Char.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ module Data.Char
charString (Char s) = s

foreign import toCharCode
"function toCharCode(c){\
\ return c.charCodeAt(0);\
\}" :: Char -> Number

foreign import fromCharCode
"function fromCharCode(c){\
\ return String.fromCharCode(c);\
\}" :: Number -> Char
"""
function toCharCode(c) {
return c.charCodeAt(0);
}
""" :: Char -> Number

foreign import fromCharCode
"""
function fromCharCode(c) {
return String.fromCharCode(c);
}
""" :: Number -> Char

instance eqChar :: Eq Char where
(==) (Char a) (Char b) = a == b
Expand Down
200 changes: 118 additions & 82 deletions src/Data/String.purs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ module Data.String
import Data.Function

foreign import _charAt
"function _charAt(i, s, Just, Nothing) {\
\ if (i < 0 || i >= s.length) return Nothing;\
\ else return Just(s.charAt(i));\
\}" :: forall a. Fn4 Number String (a -> Maybe a) (Maybe a) (Maybe Char)
"""
function _charAt(i, s, Just, Nothing) {
if (i < 0 || i >= s.length) return Nothing;
else return Just(s.charAt(i));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

return i >= 0 && i < s.length ? Just(s.charAt(i)) : Nothing;

Seems a tad cleaner to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Sorry, I literally just merged as your message popped up. If you want to send another PR, I'll merge it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. Thanks for the quick merge!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#17

}
""" :: forall a. Fn4 Number String (a -> Maybe a) (Maybe a) (Maybe Char)

charAt :: Number -> String -> Maybe Char
charAt n s = runFn4 _charAt n s Just Nothing
Expand All @@ -38,116 +40,150 @@ module Data.String
fromChar = charString

foreign import _charCodeAt
"function _charCodeAt(i, s, Just, Nothing) {\
\ if (i < 0 || i >= s.length) return Nothing;\
\ else return Just(s.charCodeAt(i));\
\}" :: forall a. Fn4 Number String (a -> Maybe a) (Maybe a) (Maybe Number)
"""
function _charCodeAt(i, s, Just, Nothing) {
if (i < 0 || i >= s.length) return Nothing;
else return Just(s.charCodeAt(i));
}
""" :: forall a. Fn4 Number String (a -> Maybe a) (Maybe a) (Maybe Number)

charCodeAt :: Number -> String -> Maybe Number
charCodeAt n s = runFn4 _charCodeAt n s Just Nothing

foreign import fromCharArray
"function fromCharArray(a) {\
\ return a.join(''); \
\}" :: [Char] -> String
"""
function fromCharArray(a) {
return a.join('');
}
""" :: [Char] -> String

foreign import indexOf
"function indexOf(x) {\
\ return function(s) {\
\ return s.indexOf(x);\
\ }; \
\}" :: String -> String -> Number
"""
function indexOf(x) {
return function(s) {
return s.indexOf(x);
};
}
""" :: String -> String -> Number

foreign import indexOf'
"function indexOf$prime(x) {\
\ return function(startAt) {\
\ return function(s) {\
\ return s.indexOf(x, startAt);\
\ }; \
\ }; \
\}" :: String -> Number -> String -> Number
"""
function indexOf$prime(x) {
return function(startAt) {
return function(s) {
return s.indexOf(x, startAt);
};
};
}
""" :: String -> Number -> String -> Number

foreign import lastIndexOf
"function lastIndexOf(x) {\
\ return function(s) {\
\ return s.lastIndexOf(x);\
\ };\
\}" :: String -> String -> Number
"""
function lastIndexOf(x) {
return function(s) {
return s.lastIndexOf(x);
};
}
""" :: String -> String -> Number

foreign import lastIndexOf'
"function lastIndexOf$prime(x) {\
\ return function(startAt) {\
\ return function(s) {\
\ return s.lastIndexOf(x, startAt);\
\ }; \
\ }; \
\}" :: String -> Number -> String -> Number
"""
function lastIndexOf$prime(x) {
return function(startAt) {
return function(s) {
return s.lastIndexOf(x, startAt);
};
};
}
""" :: String -> Number -> String -> Number

foreign import length
"function length(s) {\
\ return s.length;\
\}" :: String -> Number
"""
function length(s) {
return s.length;
}
""" :: String -> Number

foreign import localeCompare
"function localeCompare(s1) {\
\ return function(s2) {\
\ return s1.localeCompare(s2);\
\ };\
\}" :: String -> String -> Number
"""
function localeCompare(s1) {
return function(s2) {
return s1.localeCompare(s2);
};
}
""" :: String -> String -> Number

foreign import replace
"function replace(s1) {\
\ return function(s2) {\
\ return function(s3) {\
\ return s3.replace(s1, s2);\
\ };\
\ };\
\}" :: String -> String -> String -> String
"""
function replace(s1) {
return function(s2) {
return function(s3) {
return s3.replace(s1, s2);
};
};
}
""" :: String -> String -> String -> String

foreign import take
"function take(n) {\
\ return function(s) {\
\ return s.substr(0, n);\
\ };\
\}" :: Number -> String -> String
"""
function take(n) {
return function(s) {
return s.substr(0, n);
};
}
""" :: Number -> String -> String

foreign import drop
"function drop(n) {\
\ return function(s) {\
\ return s.substr(n);\
\ };\
\}" :: Number -> String -> String
"""
function drop(n) {
return function(s) {
return s.substr(n);
};
}
""" :: Number -> String -> String

foreign import split
"function split(sep) {\
\ return function(s) {\
\ return s.split(sep);\
\ };\
\}" :: String -> String -> [String]
"""
function split(sep) {
return function(s) {
return s.split(sep);
};
}
""" :: String -> String -> [String]

foreign import toCharArray
"function toCharArray(s) {\
\ return s.split('');\
\}" :: String -> [Char]
"""
function toCharArray(s) {
return s.split('');
}
""" :: String -> [Char]

foreign import toLower
"function toLower(s) {\
\ return s.toLowerCase();\
\}" :: String -> String
"""
function toLower(s) {
return s.toLowerCase();
}
""" :: String -> String

foreign import toUpper
"function toUpper(s) {\
\ return s.toUpperCase();\
\}" :: String -> String
"""
function toUpper(s) {
return s.toUpperCase();
}
""" :: String -> String

foreign import trim
"function trim(s) {\
\ return s.trim();\
\}" :: String -> String
"""
function trim(s) {
return s.trim();
}
""" :: String -> String

foreign import joinWith
"function joinWith (s) {\
\ return function (xs) {\
\ return xs.join(s);\
\ };\
\}" :: String -> [String] -> String
"""
function joinWith(s) {
return function(xs) {
return xs.join(s);
};
}
""" :: String -> [String] -> String
Loading