generic string instructions and more documentation
This commit is contained in:
parent
91bd09c00f
commit
2d6b888e2e
@ -286,6 +286,17 @@ instructionVectorFirst primAccessor vectorAccessor state =
|
||||
_ -> state
|
||||
_ -> state
|
||||
|
||||
-- |Based on a vector lens, takes the first item from the top vector on the vector stack
|
||||
-- and creates a vector wrapping that first item, pushing it back onto the stack.
|
||||
instructionVectorFromFirstPrim :: Lens' State [[a]] -> State -> State
|
||||
instructionVectorFromFirstPrim accessor state =
|
||||
case uncons (view accessor state) of
|
||||
Just (v1, vs) ->
|
||||
case uncons v1 of
|
||||
Just (vp1, _) -> state & accessor .~ ([vp1] : vs)
|
||||
_ -> state
|
||||
_ -> state
|
||||
|
||||
-- |Based on two lenses, one of a primitive type and the next of a vector type,
|
||||
-- Takes the last item from the top vector and places it onto the passed primitive stack.
|
||||
instructionVectorLast :: Lens' State [a] -> Lens' State [[a]] -> State -> State
|
||||
@ -297,6 +308,17 @@ instructionVectorLast primAccessor vectorAccessor state =
|
||||
_ -> state
|
||||
_ -> state
|
||||
|
||||
-- |Based on a vector lens, takes the last item from the top vector on the vector stack
|
||||
-- and creates a vector wrapping that last item, pushing it back onto the stack.
|
||||
instructionVectorFromLastPrim :: Lens' State [[a]] -> State -> State
|
||||
instructionVectorFromLastPrim accessor state =
|
||||
case uncons (view accessor state) of
|
||||
Just (v1, vs) ->
|
||||
case uncons (drop (length v1 - 1) v1) of
|
||||
Just (vp1, _) -> state & accessor .~ ([vp1] : vs)
|
||||
_ -> state
|
||||
_ -> state
|
||||
|
||||
-- |Based on two lenses, one of a primitive type and the next of a vector type,
|
||||
-- Takes the Nth item from the top vector and places it onto the passed primitive stack
|
||||
-- based on an int from the int stack.
|
||||
@ -307,6 +329,16 @@ instructionVectorNth primAccessor vectorAccessor state@(State {_int = i1 : is})
|
||||
_ -> state
|
||||
instructionVectorNth _ _ state= state
|
||||
|
||||
-- |Based on a vector lens, takes the Nth item from the top vector on the vector stack
|
||||
-- and creates a vector wrapping that Nth item, pushing it back onto the stack. N is
|
||||
-- the top item on the int stack.
|
||||
instructionVectorFromNthPrim :: Lens' State [[a]] -> State -> State
|
||||
instructionVectorFromNthPrim accessor state@(State {_int = i1 : is}) =
|
||||
case uncons (view accessor state) of
|
||||
Just (v1, vs) -> state{_int = is} & accessor .~ ([v1 !! absNum i1 v1] : vs)
|
||||
_ -> state
|
||||
instructionVectorFromNthPrim _ state = state
|
||||
|
||||
-- |Takes the top vector, removes the first item of said vector, and pushes the result back to top
|
||||
-- of the stack, based on a lens.
|
||||
instructionRest :: Lens' State [[a]] -> State -> State
|
||||
@ -366,6 +398,15 @@ instructionVectorContains primAccessor vectorAccessor state@(State {_bool = bs})
|
||||
(Just (v1, vs), Just (p1, ps)) -> state{_bool = (findSubA v1 [p1] /= -1) : bs} & vectorAccessor .~ vs & primAccessor .~ ps
|
||||
_ -> state
|
||||
|
||||
-- |Based on a vector lens and the two vectors on the top of said stack.
|
||||
-- If the second vector can be found within the first vector, True is pushed to the
|
||||
-- bool stack. If not, False is pushed to the bool stack.
|
||||
instructionVectorContainsVector :: Eq a => Lens' State [[a]] -> State -> State
|
||||
instructionVectorContainsVector accessor state@(State {_bool = bs}) =
|
||||
case uncons (view accessor state) of
|
||||
Just (v1, v2 : vs) -> state & accessor .~ vs & bool .~ ((findSubA v1 v2 /= (-1)) : bs)
|
||||
_ -> state
|
||||
|
||||
-- |Based on two lenses, one of a primitive type and the next of a vector type,
|
||||
-- finds the first index of the top item in the primitive stack inside of the
|
||||
-- top vector from the vector stack and pushes the result to the int stack.
|
||||
@ -375,6 +416,14 @@ instructionVectorIndexOf primAccessor vectorAccessor state =
|
||||
(Just (v1, vs), Just (p1, ps)) -> (state & vectorAccessor .~ vs & primAccessor .~ ps) & int .~ (findSubA v1 [p1] : view int (state & vectorAccessor .~ vs & primAccessor .~ ps))
|
||||
_ -> state
|
||||
|
||||
-- |Based on a vector lens and the two vectors on top of said stack. Searches and pushes the
|
||||
-- index of the second vector inside of the first vector to the int stack. Pushes -1 if not found.
|
||||
instructionVectorIndexOfVector :: Eq a => Lens' State [[a]] -> State -> State
|
||||
instructionVectorIndexOfVector accessor state@(State {_int = is}) =
|
||||
case uncons (view accessor state) of
|
||||
Just (v1, v2 : vs) -> state & accessor .~ vs & int .~ (findSubA v1 v2 : is)
|
||||
_ -> state
|
||||
|
||||
-- |Based on two lenses, one of a primitive type and the next of a vector type,
|
||||
-- finds the amount of times the top item in the primitive stack occurs inside of the
|
||||
-- top vector from the vector stack and pushes the result to the int stack.
|
||||
@ -384,6 +433,15 @@ instructionVectorOccurrencesOf primAccessor vectorAccessor state =
|
||||
(Just (v1, vs), Just (p1, ps)) -> (state & vectorAccessor .~ vs & primAccessor .~ ps) & int .~ (amtOccurences v1 [p1] : view int (state & vectorAccessor .~ vs & primAccessor .~ ps))
|
||||
_ -> state
|
||||
|
||||
-- |Based on a vector lens and the top two vectors in said stack,
|
||||
-- Counts the amount of occurrences of the second vector in the first
|
||||
-- vector. Pushes the result to the string stack.
|
||||
instructionVectorOccurrencesOfVector :: Eq a => Lens' State [[a]] -> State -> State
|
||||
instructionVectorOccurrencesOfVector accessor state@(State {_int = is}) =
|
||||
case uncons (view accessor state) of
|
||||
Just (v1, v2 : vs) -> state & accessor .~ vs & int .~ (amtOccurences v1 v2 : is)
|
||||
_ -> state
|
||||
|
||||
-- |This function parses the primitives inside a vector type and pushes that vector split into
|
||||
-- lists of size one onto the respective vector stack. Based on a vector lens.
|
||||
instructionVectorParseToPrim :: Lens' State [[a]] -> State -> State
|
||||
@ -392,7 +450,7 @@ instructionVectorParseToPrim accessor state =
|
||||
Just (x1, xs) -> state & accessor .~ (chunksOf 1 x1 <> xs)
|
||||
_ -> state
|
||||
|
||||
-- |Based on two lenses, one of a primitive type and the next of a vector type,
|
||||
-- |Based on two lenses, one of a primitive type and the next of a vector type.
|
||||
-- Sets the Nth index inside of the top vector from the vector stack to the top value
|
||||
-- from the primitive stack. N is based on an int from the top of the int stack.
|
||||
instructionVectorSetNth :: Lens' State [a] -> Lens' State [[a]] -> State -> State
|
||||
@ -402,28 +460,53 @@ instructionVectorSetNth primAccessor vectorAccessor state@(State {_int = i1 : is
|
||||
_ -> state
|
||||
instructionVectorSetNth _ _ state = state
|
||||
|
||||
-- |Based on two lenses, one of a primitive type and the next of a vector type.
|
||||
-- Splits the vector on top of the vector stack with the top primitive and pushes the
|
||||
-- result to the original vector stack.
|
||||
instructionVectorSplitOn :: Eq a => Lens' State [a] -> Lens' State [[a]] -> State -> State
|
||||
instructionVectorSplitOn primAccessor vectorAccessor state =
|
||||
case (uncons (view vectorAccessor state), uncons (view primAccessor state)) of
|
||||
(Just (v1, vs), Just (p1, ps)) -> state & primAccessor .~ ps & vectorAccessor .~ (reverse (splitOn [p1] v1) <> vs)
|
||||
_ -> state
|
||||
|
||||
-- |Based on a vector lens and top two items of said stack, splits the
|
||||
-- first vector based on the second vector and pushes the result to the
|
||||
-- original vector stack.
|
||||
instructionVectorSplitOnVector :: Eq a => Lens' State [[a]] -> State -> State
|
||||
instructionVectorSplitOnVector accessor state =
|
||||
case uncons (view accessor state) of
|
||||
Just (v1, v2 : vs) -> state & accessor .~ (reverse (splitOn v2 v1) <> vs)
|
||||
_ -> state
|
||||
|
||||
-- |Based on two lenses, one of a primitive type and the next of a vector type,
|
||||
-- replaces all occurrences inside of the top vector from the vector stack with two values from
|
||||
-- the primitive stack. The top of the primitive stack is the old value to be replaced. The second item
|
||||
-- in the primitive stack is the new value to replace the old one.
|
||||
instructionVectorReplace :: Eq a => Lens' State [a] -> Lens' State [[a]] -> State -> State
|
||||
instructionVectorReplace primAccessor vectorAccessor state =
|
||||
instructionVectorReplace :: Eq a => Lens' State [a] -> Lens' State [[a]] -> Maybe Int -> State -> State
|
||||
instructionVectorReplace primAccessor vectorAccessor amt state =
|
||||
case (uncons (view vectorAccessor state), uncons (view primAccessor state)) of
|
||||
(Just (v1, vs), Just (p1, p2 : ps)) -> state & vectorAccessor .~ (replace v1 [p1] [p2] Nothing : vs) & primAccessor .~ ps
|
||||
(Just (v1, vs), Just (p1, p2 : ps)) -> state & vectorAccessor .~ (replace v1 [p1] [p2] amt: vs) & primAccessor .~ ps
|
||||
_ -> state
|
||||
|
||||
-- |Based on two lenses, one of a primitive type and the next of a vector type,
|
||||
-- replaces the first occurrence inside of the top vector from the vector stack with two values from
|
||||
-- the primitive stack. The top of the primitive stack is the old value to be replaced. The second item
|
||||
-- in the primitive stack is the new value to replace the old one.
|
||||
instructionVectorReplaceFirst :: Eq a => Lens' State [a] -> Lens' State [[a]] -> State -> State
|
||||
instructionVectorReplaceFirst primAccessor vectorAccessor state =
|
||||
case (uncons (view vectorAccessor state), uncons (view primAccessor state)) of
|
||||
(Just (v1, vs), Just (p1, p2 : ps)) -> state & vectorAccessor .~ (replace v1 [p1] [p2] (Just 1) : vs) & primAccessor .~ ps
|
||||
-- |Based on a vector lens and the top three vectors on said stack.
|
||||
-- Inside of the first vector, replaces the number of instances specified
|
||||
-- by the Maybe Int parameter of the second vector with the third vector.
|
||||
-- If amt is Nothing, replaces all instances.
|
||||
instructionVectorReplaceVector :: Eq a => Lens' State [[a]] -> Maybe Int -> State -> State
|
||||
instructionVectorReplaceVector accessor amt state =
|
||||
case uncons (view accessor state) of
|
||||
Just (v1, v2 : v3 : vs) -> state & accessor .~ (replace v1 v2 v3 amt : vs)
|
||||
_ -> state
|
||||
|
||||
-- |Based on a vector lens, the top three vectors on said stack, and the top int on the int stack.
|
||||
-- Inside of the first vector, replaces the number of instances specified
|
||||
-- by the top of the int stack of the second vector with the third vector.
|
||||
instructionVectorReplaceVectorN :: Eq a => Lens' State [[a]] -> State -> State
|
||||
instructionVectorReplaceVectorN accessor state@(State {_int = i1 : is}) = instructionVectorReplaceVector accessor (Just i1) state{_int = is}
|
||||
instructionVectorReplaceVectorN _ state = state
|
||||
|
||||
-- |Based on two lenses, one of a primitive type and the next of a vector type,
|
||||
-- removes all occurrences inside of the top vector from the vector stack where the top
|
||||
-- Removes all occurrences inside of the top vector from the vector stack where the top
|
||||
-- item from the primitive stack equals a primitive inside of the vector stack.
|
||||
instructionVectorRemove :: Eq a => Lens' State [a] -> Lens' State [[a]] -> State -> State
|
||||
instructionVectorRemove primAccessor vectorAccessor state =
|
||||
@ -431,6 +514,22 @@ instructionVectorRemove primAccessor vectorAccessor state =
|
||||
(Just (v1, vs), Just (p1, ps)) -> state & vectorAccessor .~ (replace v1 [p1] [] Nothing : vs) & primAccessor .~ ps
|
||||
_ -> state
|
||||
|
||||
-- |Based on a vector lens and the two vectors on top of said stack.
|
||||
-- Inside of the first vector, removes the number of instances specified
|
||||
-- by the Maybe Int parameter of the second vector. Nothing removes all instances.
|
||||
instructionVectorRemoveVector :: Eq a => Lens' State [[a]] -> Maybe Int -> State -> State
|
||||
instructionVectorRemoveVector accessor amt state =
|
||||
case uncons (view accessor state) of
|
||||
Just (v1, v2 : vs) -> state & accessor .~ (replace v1 v2 [] amt : vs)
|
||||
_ -> state
|
||||
|
||||
-- |Based on a vector lens, the top two vectors on said stack, and the top int on the int stack.
|
||||
-- Inside of the first vector, removes the number of instances specified
|
||||
-- by the top of the int stack of the second vector.
|
||||
instructionVectorRemoveVectorN :: Eq a => Lens' State [[a]] -> State -> State
|
||||
instructionVectorRemoveVectorN accessor state@(State {_int = i1 : is}) = instructionVectorRemoveVector accessor (Just i1) state{_int = is}
|
||||
instructionVectorRemoveVectorN _ state = state
|
||||
|
||||
-- |Based on two lenses, one of a primitive type and the next of a vector type,
|
||||
-- removes the first occurrence inside of the top vector from the vector stack where the top
|
||||
-- item from the primitive stack equals a primitive inside of the vector stack.
|
||||
@ -467,3 +566,24 @@ instructionVectorSortReverse accessor state =
|
||||
case uncons (view accessor state) of
|
||||
Just (x, xs) -> state & accessor .~ (sortBy (comparing Data.Ord.Down) x : xs)
|
||||
_ -> state
|
||||
|
||||
-- |Takes a vector lens, a primitive lens, and the top of the int stack
|
||||
-- Inserts the top of the primitive stack into a index specified by the
|
||||
-- top of the int stack into the top vector from the vector stack.
|
||||
instructionVectorInsert :: Lens' State [a] -> Lens' State [[a]] -> State -> State
|
||||
instructionVectorInsert primAccessor vectorAccessor state@(State {_int = i1 : is}) =
|
||||
case (uncons (view vectorAccessor state{_int = is}), uncons (view primAccessor state{_int = is})) of
|
||||
(Just (v1, vs), Just (p1, ps)) -> state{_int = is} & primAccessor .~ ps & vectorAccessor .~ (combineTuple p1 (splitAt i1 v1) : vs)
|
||||
_ -> state
|
||||
instructionVectorInsert _ _ state = state
|
||||
|
||||
-- |Takes a vector lens and inserts the second vector on the vector stack
|
||||
-- into the first vector on the vector stack based on an int from the
|
||||
-- int stack.
|
||||
instructionVectorInsertVector :: Lens' State [[a]] -> State -> State
|
||||
instructionVectorInsertVector accessor state@(State {_int = i1 : is}) =
|
||||
case uncons (view accessor state) of
|
||||
Just (v1, v2 : vs) ->
|
||||
state{_int = is} & accessor .~ (combineTupleList v2 (splitAt i1 v1) : vs)
|
||||
_ -> state
|
||||
instructionVectorInsertVector _ state = state
|
||||
|
@ -5,13 +5,16 @@ import HushGP.Instructions.GenericInstructions
|
||||
import Data.List.Split
|
||||
import Control.Lens
|
||||
|
||||
-- |Utility String: Whitespack characters.
|
||||
-- shamelessly stolen from https://hackage.haskell.org/package/MissingH-1.6.0.1/docs/src/Data.String.Utils.html#strip
|
||||
wschars :: String
|
||||
wschars = " \t\r\n"
|
||||
|
||||
-- |Utility Function: Strips a string of its whitespace on both sides.
|
||||
strip :: String -> String
|
||||
strip = lstrip . rstrip
|
||||
|
||||
-- |Utility Function: Strips a string of its whitespace on the left side.
|
||||
lstrip :: String -> String
|
||||
lstrip s = case s of
|
||||
[] -> []
|
||||
@ -19,99 +22,136 @@ lstrip s = case s of
|
||||
then lstrip xs
|
||||
else s
|
||||
|
||||
-- this is a tad inefficient init
|
||||
-- |Utility Function: Strips a string of its whitespace on the right side.
|
||||
-- this is a tad inefficient
|
||||
rstrip :: String -> String
|
||||
rstrip = reverse . lstrip . reverse
|
||||
|
||||
-- |Concats the top two strings on the string stack and pushes the result.
|
||||
instructionStringConcat :: State -> State
|
||||
instructionStringConcat = instructionConcat string
|
||||
|
||||
-- |Swaps the top two strings on the string stack.
|
||||
instructionStringSwap :: State -> State
|
||||
instructionStringSwap = instructionSwap string
|
||||
|
||||
-- |Inserts the second string on the string stack into the first string
|
||||
-- on the string stack based on an int from the int stack.
|
||||
instructionStringInsertString :: State -> State
|
||||
instructionStringInsertString state@(State{_string = s1 : s2 : ss, _int = i1 : is}) = state {_string = combineTupleList s2 (splitAt i1 s1) : ss, _int = is}
|
||||
instructionStringInsertString state = state
|
||||
instructionStringInsertString = instructionVectorInsertVector string
|
||||
-- instructionStringInsertString state@(State{_string = s1 : s2 : ss, _int = i1 : is}) = state {_string = combineTupleList s2 (splitAt i1 s1) : ss, _int = is}
|
||||
-- instructionStringInsertString state = state
|
||||
|
||||
-- |Takes the first string from the string stack and pushes the first character
|
||||
-- back to the string stack as a string.
|
||||
instructionStringFromFirstChar :: State -> State
|
||||
instructionStringFromFirstChar state@(State {_string = (schar : _) : ss}) = state {_string = [schar] : ss}
|
||||
instructionStringFromFirstChar state = state
|
||||
instructionStringFromFirstChar = instructionVectorFromFirstPrim string
|
||||
-- instructionStringFromFirstChar state@(State {_string = (schar : _) : ss}) = state {_string = [schar] : ss}
|
||||
-- instructionStringFromFirstChar state = state
|
||||
|
||||
-- |Takes the first string from the string stack and pushes the last character
|
||||
-- back to the string stack as a string.
|
||||
instructionStringFromLastChar :: State -> State
|
||||
instructionStringFromLastChar state@(State {_string = s1 : ss}) =
|
||||
if not $ null s1
|
||||
then state {_string = [last s1] : ss}
|
||||
else state
|
||||
instructionStringFromLastChar state = state
|
||||
instructionStringFromLastChar = instructionVectorFromLastPrim string
|
||||
-- instructionStringFromLastChar state@(State {_string = s1 : ss}) =
|
||||
-- if not $ null s1
|
||||
-- then state {_string = [last s1] : ss}
|
||||
-- else state
|
||||
-- instructionStringFromLastChar state = state
|
||||
|
||||
-- |Takes the first string from the string stack and pushes the Nth character
|
||||
-- back to the string stack as a string. N in is the top int of the int stack.
|
||||
instructionStringFromNthChar :: State -> State
|
||||
instructionStringFromNthChar state@(State {_string = s1 : ss, _int = i1 : is}) = state{_string = [s1 !! absNum i1 s1] : ss, _int = is}
|
||||
instructionStringFromNthChar state = state
|
||||
instructionStringFromNthChar = instructionVectorFromNthPrim string
|
||||
-- instructionStringFromNthChar state@(State {_string = s1 : ss, _int = i1 : is}) = state{_string = [s1 !! absNum i1 s1] : ss, _int = is}
|
||||
-- instructionStringFromNthChar state = state
|
||||
|
||||
-- |Takes the first two strings from the top of the string stack. Looks for and pushed the
|
||||
-- index of the second substring inside of the first substring to the int stack.
|
||||
-- If not found, returns -1.
|
||||
instructionStringIndexOfString :: State -> State
|
||||
instructionStringIndexOfString state@(State {_string = s1 : s2 : ss, _int = is}) = state {_string = ss, _int = findSubA s1 s2 : is}
|
||||
instructionStringIndexOfString state = state
|
||||
instructionStringIndexOfString = instructionVectorIndexOfVector string
|
||||
-- instructionStringIndexOfString state@(State {_string = s1 : s2 : ss, _int = is}) = state {_string = ss, _int = findSubA s1 s2 : is}
|
||||
-- instructionStringIndexOfString state = state
|
||||
|
||||
-- |Takes the first two strings from the top of the string stack. Pushes True to the
|
||||
-- bool stack if the second string is contained within the first string. Pushes False otherwise.
|
||||
instructionStringContainsString :: State -> State
|
||||
instructionStringContainsString state@(State {_string = s1 : s2 : ss, _bool = bs}) = state {_string = ss, _bool = (findSubA s1 s2 /= -1) : bs}
|
||||
instructionStringContainsString state = state
|
||||
instructionStringContainsString = instructionVectorContainsVector string
|
||||
-- instructionStringContainsString state@(State {_string = s1 : s2 : ss, _bool = bs}) = state {_string = ss, _bool = (findSubA s1 s2 /= -1) : bs}
|
||||
-- instructionStringContainsString state = state
|
||||
|
||||
-- |Takes the first two strings from the top of the string stack. Splits the first string
|
||||
-- based on the second string and pushes the result to the string stack.
|
||||
-- pysh reverses this. Check this for propeller
|
||||
instructionStringSplitOnString :: State -> State
|
||||
instructionStringSplitOnString state@(State {_string = s1 : s2 : ss}) = state {_string = reverse $ splitOn s2 s1 <> ss}
|
||||
instructionStringSplitOnString state = state
|
||||
instructionStringSplitOnString = instructionVectorSplitOnVector string
|
||||
-- instructionStringSplitOnString state@(State {_string = s1 : s2 : ss}) = state {_string = reverse $ splitOn s2 s1 <> ss}
|
||||
-- instructionStringSplitOnString state = state
|
||||
|
||||
-- |Takes the first three strings from the top of the string stack. Replaces the first instance of
|
||||
-- the second string within the first string with the third string. Pushes the result to the string stack.
|
||||
instructionStringReplaceFirstString :: State -> State
|
||||
instructionStringReplaceFirstString state@(State {_string = s1 : s2 : s3 : ss}) = state {_string = replace s1 s2 s3 (Just 1) : ss}
|
||||
instructionStringReplaceFirstString state = state
|
||||
instructionStringReplaceFirstString = instructionVectorReplaceVector string (Just 1)
|
||||
|
||||
-- |Takes the first three strings from the top of the string stack. Replaces the number of instances based on the of the int stack of
|
||||
-- the second string within the first string with the third string. Pushes the result to the string stack.
|
||||
instructionStringReplaceNString :: State -> State
|
||||
instructionStringReplaceNString state@(State {_string = s1 : s2 : s3 : ss, _int = i1 : is}) = state{_string = replace s1 s2 s3 (Just i1) : ss, _int = is}
|
||||
instructionStringReplaceNString state = state
|
||||
instructionStringReplaceNString = instructionVectorReplaceVectorN string
|
||||
|
||||
-- |Takes the first three strings from the top of the string stack. Replaces all instances of
|
||||
-- the second string within the first string with the third string. Pushes the result to the string stack.
|
||||
instructionStringReplaceAllString :: State -> State
|
||||
instructionStringReplaceAllString state@(State {_string = s1 : s2 : s3 : ss}) = state{_string = replace s1 s2 s3 Nothing : ss}
|
||||
instructionStringReplaceAllString state = state
|
||||
instructionStringReplaceAllString = instructionVectorReplaceVector string Nothing
|
||||
|
||||
-- |Takes the first two strings from the top of the string stack. Removes the first instance of
|
||||
-- the second string. Pushes the result to the string stack.
|
||||
instructionStringRemoveFirstString :: State -> State
|
||||
instructionStringRemoveFirstString state@(State {_string = s1 : s2 : ss}) = state{_string = replace s1 s2 "" (Just 1) : ss}
|
||||
instructionStringRemoveFirstString state = state
|
||||
instructionStringRemoveFirstString = instructionVectorRemoveVector string (Just 1)
|
||||
|
||||
-- |Takes the first two strings from the top of the string stack. Removes N instances
|
||||
-- based on the top int from the int stack of the second string. Pushes the result to the string stack.
|
||||
instructionStringRemoveNString :: State -> State
|
||||
instructionStringRemoveNString state@(State {_string = s1 : s2 : ss, _int = i1 : is}) = state{_string = replace s1 s2 "" (Just i1) : ss, _int = is}
|
||||
instructionStringRemoveNString state = state
|
||||
instructionStringRemoveNString = instructionVectorRemoveVectorN string
|
||||
|
||||
-- |Takes the first two strings from the top of the string stack. Removes all instances of
|
||||
-- the second string. Pushes the result to the string stack.
|
||||
instructionStringRemoveAllString :: State -> State
|
||||
instructionStringRemoveAllString state@(State {_string = s1 : s2 : ss}) = state{_string = replace s1 s2 "" Nothing : ss}
|
||||
instructionStringRemoveAllString state = state
|
||||
instructionStringRemoveAllString = instructionVectorRemoveVector string Nothing
|
||||
|
||||
-- |Counts the amount of occurrences of the second string in the first
|
||||
-- string. Pushes the result to the string stack.
|
||||
instructionStringOccurrencesOfString :: State -> State
|
||||
instructionStringOccurrencesOfString state@(State {_string = s1 : s2 : ss, _int = is}) = state{_string = ss, _int = amtOccurences s1 s2 : is}
|
||||
instructionStringOccurrencesOfString state = state
|
||||
instructionStringOccurrencesOfString = instructionVectorOccurrencesOfVector string
|
||||
|
||||
-- |Inserts the top char of the char stack into the top string of the string
|
||||
-- stack based on an index from the top int of the int stack.
|
||||
instructionStringInsertChar :: State -> State
|
||||
instructionStringInsertChar state@(State {_string = s1 : ss, _char = c1 : cs, _int = i1 : is}) = state{_string = combineTuple c1 (splitAt i1 s1) : ss, _char = cs, _int = is}
|
||||
instructionStringInsertChar state = state
|
||||
instructionStringInsertChar = instructionVectorInsert char string
|
||||
|
||||
-- |Pushes True to the bool stack if the top char on the char stack is within the
|
||||
-- top string on the string stack. Pushes False otherwise.
|
||||
instructionStringContainsChar :: State -> State
|
||||
instructionStringContainsChar = instructionVectorContains char string
|
||||
|
||||
-- |Pushes the first index found of the top char of the char stack within the
|
||||
-- first string in the string stack to the int stack.
|
||||
instructionStringIndexOfChar :: State -> State
|
||||
instructionStringIndexOfChar = instructionVectorIndexOf char string
|
||||
|
||||
-- |@TODO
|
||||
instructionStringSplitOnChar :: State -> State
|
||||
instructionStringSplitOnChar state@(State {_string = s1 : ss, _char = c1 : cs}) = state {_string = reverse $ splitOn [c1] s1 <> ss, _char = cs}
|
||||
instructionStringSplitOnChar state = state
|
||||
instructionStringSplitOnChar = instructionVectorSplitOn char string
|
||||
|
||||
instructionStringReplaceFirstChar :: State -> State
|
||||
instructionStringReplaceFirstChar = instructionVectorReplaceFirst char string
|
||||
instructionStringReplaceFirstChar = instructionVectorReplace char string (Just 1)
|
||||
|
||||
instructionStringReplaceNChar :: State -> State
|
||||
instructionStringReplaceNChar state@(State {_string = s1 : ss, _char = c1 : c2 : cs, _int = i1 : is}) = state{_string = replace s1 [c1] [c2] (Just i1) : ss, _char = cs, _int = is}
|
||||
instructionStringReplaceNChar state = state
|
||||
|
||||
instructionStringReplaceAllChar :: State -> State
|
||||
instructionStringReplaceAllChar = instructionVectorReplace char string
|
||||
instructionStringReplaceAllChar = instructionVectorReplace char string Nothing
|
||||
|
||||
instructionStringRemoveFirstChar :: State -> State
|
||||
instructionStringRemoveFirstChar state@(State {_string = s1 : ss, _char = c1 : cs}) = state {_string = replace s1 [c1] "" (Just 1) : ss, _char = cs}
|
||||
|
@ -55,10 +55,10 @@ instructionVectorBoolSetNth :: State -> State
|
||||
instructionVectorBoolSetNth = instructionVectorSetNth bool vectorBool
|
||||
|
||||
instructionVectorBoolReplace :: State -> State
|
||||
instructionVectorBoolReplace = instructionVectorReplace bool vectorBool
|
||||
instructionVectorBoolReplace = instructionVectorReplace bool vectorBool Nothing
|
||||
|
||||
instructionVectorBoolReplaceFirst :: State -> State
|
||||
instructionVectorBoolReplaceFirst = instructionVectorReplaceFirst bool vectorBool
|
||||
instructionVectorBoolReplaceFirst = instructionVectorReplace bool vectorBool (Just 1)
|
||||
|
||||
instructionVectorBoolRemove :: State -> State
|
||||
instructionVectorBoolRemove = instructionVectorRemove bool vectorBool
|
||||
|
@ -55,10 +55,10 @@ instructionVectorCharSetNth :: State -> State
|
||||
instructionVectorCharSetNth = instructionVectorSetNth char vectorChar
|
||||
|
||||
instructionVectorCharReplace :: State -> State
|
||||
instructionVectorCharReplace = instructionVectorReplace char vectorChar
|
||||
instructionVectorCharReplace = instructionVectorReplace char vectorChar Nothing
|
||||
|
||||
instructionVectorCharReplaceFirst :: State -> State
|
||||
instructionVectorCharReplaceFirst = instructionVectorReplaceFirst char vectorChar
|
||||
instructionVectorCharReplaceFirst = instructionVectorReplace char vectorChar (Just 1)
|
||||
|
||||
instructionVectorCharRemove :: State -> State
|
||||
instructionVectorCharRemove = instructionVectorRemove char vectorChar
|
||||
|
@ -55,10 +55,10 @@ instructionVectorFloatSetNth :: State -> State
|
||||
instructionVectorFloatSetNth = instructionVectorSetNth float vectorFloat
|
||||
|
||||
instructionVectorFloatReplace :: State -> State
|
||||
instructionVectorFloatReplace = instructionVectorReplace float vectorFloat
|
||||
instructionVectorFloatReplace = instructionVectorReplace float vectorFloat Nothing
|
||||
|
||||
instructionVectorFloatReplaceFirst :: State -> State
|
||||
instructionVectorFloatReplaceFirst = instructionVectorReplaceFirst float vectorFloat
|
||||
instructionVectorFloatReplaceFirst = instructionVectorReplace float vectorFloat (Just 1)
|
||||
|
||||
instructionVectorFloatRemove :: State -> State
|
||||
instructionVectorFloatRemove = instructionVectorRemove float vectorFloat
|
||||
|
@ -55,10 +55,10 @@ instructionVectorIntSetNth :: State -> State
|
||||
instructionVectorIntSetNth = instructionVectorSetNth int vectorInt
|
||||
|
||||
instructionVectorIntReplace :: State -> State
|
||||
instructionVectorIntReplace = instructionVectorReplace int vectorInt
|
||||
instructionVectorIntReplace = instructionVectorReplace int vectorInt Nothing
|
||||
|
||||
instructionVectorIntReplaceFirst :: State -> State
|
||||
instructionVectorIntReplaceFirst = instructionVectorReplaceFirst int vectorInt
|
||||
instructionVectorIntReplaceFirst = instructionVectorReplace int vectorInt (Just 1)
|
||||
|
||||
instructionVectorIntRemove :: State -> State
|
||||
instructionVectorIntRemove = instructionVectorRemove int vectorInt
|
||||
|
@ -55,10 +55,10 @@ instructionVectorStringSetNth :: State -> State
|
||||
instructionVectorStringSetNth = instructionVectorSetNth string vectorString
|
||||
|
||||
instructionVectorStringReplace :: State -> State
|
||||
instructionVectorStringReplace = instructionVectorReplace string vectorString
|
||||
instructionVectorStringReplace = instructionVectorReplace string vectorString Nothing
|
||||
|
||||
instructionVectorStringReplaceFirst :: State -> State
|
||||
instructionVectorStringReplaceFirst = instructionVectorReplaceFirst string vectorString
|
||||
instructionVectorStringReplaceFirst = instructionVectorReplace string vectorString (Just 1)
|
||||
|
||||
instructionVectorStringRemove :: State -> State
|
||||
instructionVectorStringRemove = instructionVectorRemove string vectorString
|
||||
|
Loading…
x
Reference in New Issue
Block a user