Add ways to get substrings
This commit is contained in:
parent
74a13f59b5
commit
81cbe9f147
2 changed files with 51 additions and 6 deletions
|
@ -62,6 +62,23 @@ Elm.Native.String.make = function(elm) {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sub(start, end, str) {
|
||||||
|
return str.slice(start,end);
|
||||||
|
}
|
||||||
|
function left(n, str) {
|
||||||
|
return n < 1 ? "" : str.slice(0,n);
|
||||||
|
}
|
||||||
|
function right(n, str) {
|
||||||
|
return n < 1 ? "" : str.slice(-n);
|
||||||
|
}
|
||||||
|
function dropLeft(n, str) {
|
||||||
|
return n < 1 ? str : str.slice(n);
|
||||||
|
}
|
||||||
|
function dropRight(n, str) {
|
||||||
|
return n < 1 ? str : str.slice(0,-n);
|
||||||
|
}
|
||||||
|
|
||||||
function pad(n,chr,str) {
|
function pad(n,chr,str) {
|
||||||
var half = n - str.length / 2;
|
var half = n - str.length / 2;
|
||||||
return repeat(Math.ceil(half),chr) + str + repeat(half|0,chr);
|
return repeat(Math.ceil(half),chr) + str + repeat(half|0,chr);
|
||||||
|
@ -187,6 +204,12 @@ Elm.Native.String.make = function(elm) {
|
||||||
join: F2(join),
|
join: F2(join),
|
||||||
repeat: F2(repeat),
|
repeat: F2(repeat),
|
||||||
|
|
||||||
|
sub: F3(sub),
|
||||||
|
left: F2(left),
|
||||||
|
right: F2(right),
|
||||||
|
dropLeft: F2(dropLeft),
|
||||||
|
dropRight: F2(dropRight),
|
||||||
|
|
||||||
pad: F3(pad),
|
pad: F3(pad),
|
||||||
padLeft: F3(padLeft),
|
padLeft: F3(padLeft),
|
||||||
padRight: F3(padRight),
|
padRight: F3(padRight),
|
||||||
|
|
|
@ -5,9 +5,12 @@ module String where
|
||||||
|
|
||||||
@docs map, filter, reverse, foldl, foldr
|
@docs map, filter, reverse, foldl, foldr
|
||||||
|
|
||||||
@docs split, join
|
@docs any, all, toUpper, toLower
|
||||||
|
|
||||||
@docs repeat
|
@docs split, join, repeat
|
||||||
|
|
||||||
|
Should the next 4 exist?
|
||||||
|
@docs left, right, dropLeft, dropRight, sub
|
||||||
|
|
||||||
@docs pad, padLeft, padRight
|
@docs pad, padLeft, padRight
|
||||||
|
|
||||||
|
@ -15,10 +18,6 @@ module String where
|
||||||
|
|
||||||
@docs words, unwords, lines, unlines
|
@docs words, unwords, lines, unlines
|
||||||
|
|
||||||
@docs toUpper, toLower
|
|
||||||
|
|
||||||
@docs any, all
|
|
||||||
|
|
||||||
@docs contains, startsWith, endsWith, indices, indexes
|
@docs contains, startsWith, endsWith, indices, indexes
|
||||||
|
|
||||||
@docs toInt, toFloat
|
@docs toInt, toFloat
|
||||||
|
@ -88,6 +87,29 @@ join = Native.String.join
|
||||||
repeat : Int -> String -> String
|
repeat : Int -> String -> String
|
||||||
repeat = Native.String.repeat
|
repeat = Native.String.repeat
|
||||||
|
|
||||||
|
sub : Int -> Int -> String -> String
|
||||||
|
sub = Native.String.sub
|
||||||
|
|
||||||
|
{-|
|
||||||
|
-}
|
||||||
|
left : Int -> String -> String
|
||||||
|
left = Native.String.left
|
||||||
|
|
||||||
|
{-|
|
||||||
|
-}
|
||||||
|
right : Int -> String -> String
|
||||||
|
right = Native.String.right
|
||||||
|
|
||||||
|
{-|
|
||||||
|
-}
|
||||||
|
dropLeft : Int -> String -> String
|
||||||
|
dropLeft = Native.String.dropLeft
|
||||||
|
|
||||||
|
{-|
|
||||||
|
-}
|
||||||
|
dropRight : Int -> String -> String
|
||||||
|
dropRight = Native.String.dropRight
|
||||||
|
|
||||||
{-|
|
{-|
|
||||||
-}
|
-}
|
||||||
pad : Int -> Char -> String -> String
|
pad : Int -> Char -> String -> String
|
||||||
|
|
Loading…
Reference in a new issue