on master help sign in
Add ways to get substrings
81cbe9fEvan Czaplicki
libraries/Native/String.js+23
@@ -62,6 +62,23 @@ Elm.Native.String.make = function(elm) {
62 }
62 }
63 return result;
63 return result;
64 }
64 }
65+
66+ function sub(start, end, str) {
67+ return str.slice(start,end);
68+ }
69+ function left(n, str) {
70+ return n < 1 ? "" : str.slice(0,n);
71+ }
72+ function right(n, str) {
73+ return n < 1 ? "" : str.slice(-n);
74+ }
75+ function dropLeft(n, str) {
76+ return n < 1 ? str : str.slice(n);
77+ }
78+ function dropRight(n, str) {
79+ return n < 1 ? str : str.slice(0,-n);
80+ }
81+
65 function pad(n,chr,str) {
82 function pad(n,chr,str) {
66 var half = n - str.length / 2;
83 var half = n - str.length / 2;
67 return repeat(Math.ceil(half),chr) + str + repeat(half|0,chr);
84 return repeat(Math.ceil(half),chr) + str + repeat(half|0,chr);
@@ -187,6 +204,12 @@ Elm.Native.String.make = function(elm) {
187 join: F2(join),
204 join: F2(join),
188 repeat: F2(repeat),
205 repeat: F2(repeat),
189
206
207+ sub: F3(sub),
208+ left: F2(left),
209+ right: F2(right),
210+ dropLeft: F2(dropLeft),
211+ dropRight: F2(dropRight),
212+
190 pad: F3(pad),
213 pad: F3(pad),
191 padLeft: F3(padLeft),
214 padLeft: F3(padLeft),
192 padRight: F3(padRight),
215 padRight: F3(padRight),
libraries/String.elm+28−6
@@ -5,9 +5,12 @@ module String where
5
5
6@docs map, filter, reverse, foldl, foldr
6@docs map, filter, reverse, foldl, foldr
7
7
8−@docs split, join
8+@docs any, all, toUpper, toLower
9
9
10−@docs repeat
10+@docs split, join, repeat
11+
12+Should the next 4 exist?
13+@docs left, right, dropLeft, dropRight, sub
11
14
12@docs pad, padLeft, padRight
15@docs pad, padLeft, padRight
13
16
@@ -15,10 +18,6 @@ module String where
15
18
16@docs words, unwords, lines, unlines
19@docs words, unwords, lines, unlines
17
20
18−@docs toUpper, toLower
19−
20−@docs any, all
21−
22@docs contains, startsWith, endsWith, indices, indexes
21@docs contains, startsWith, endsWith, indices, indexes
23
22
24@docs toInt, toFloat
23@docs toInt, toFloat
@@ -88,6 +87,29 @@ join = Native.String.join
88repeat : Int -> String -> String
87repeat : Int -> String -> String
89repeat = Native.String.repeat
88repeat = Native.String.repeat
90
89
90+sub : Int -> Int -> String -> String
91+sub = Native.String.sub
92+
93+{-|
94+-}
95+left : Int -> String -> String
96+left = Native.String.left
97+
98+{-|
99+-}
100+right : Int -> String -> String
101+right = Native.String.right
102+
103+{-|
104+-}
105+dropLeft : Int -> String -> String
106+dropLeft = Native.String.dropLeft
107+
108+{-|
109+-}
110+dropRight : Int -> String -> String
111+dropRight = Native.String.dropRight
112+
91{-|
113{-|
92-}
114-}
93pad : Int -> Char -> String -> String
115pad : Int -> Char -> String -> String