Skip to content

Commit

Permalink
✨ Add string concatenation process
Browse files Browse the repository at this point in the history
  • Loading branch information
haiiro2gou committed Dec 10, 2023
1 parent 06759df commit 8debb2b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
21 changes: 21 additions & 0 deletions data/ashen_lib/functions/string/concat/.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#> ashen_lib:string/concat/
#
# Combine strings, splitting at specified characters
#
# @input storage ashen_lib:api Argument
# CharArray : string[]
# Punctuation : string[]
# @output storage ashen_lib:api
# Return : string
# @api

# Validate
execute unless data storage ashen_lib:api Argument.CharArray run tellraw @a [{"nbt": "Ashen.Global.Prefix.ERROR", "storage": "global"}, {"translate": "Ashen.Api.Error.Chars", "fallback": "Missing Argument: CharArray"}]
execute unless data storage ashen_lib:api Argument.Punctuation run data modify storage ashen_lib:api Argument.Punctuation set value [""]

# Exec
execute if data storage ashen_lib:api Argument.CharArray run function ashen_lib:string/concat/core/

# Reset
data remove storage ashen_lib:api Argument.CharArray
data remove storage ashen_lib:api Argument.Punctuation
29 changes: 29 additions & 0 deletions data/ashen_lib/functions/string/concat/core/.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#> ashen_lib:string/concat/core/
# @within function
# ashen_lib:string/concat/
# ashen_lib:string/concat/core/

# Validate
execute unless data storage ashen_lib:api Return[-1] run data modify storage ashen_lib:api Return[-1] append value ""

# Get Variable
data modify storage ashen_lib:temp Left set from storage ashen_lib:api Return[-1]
data modify storage ashen_lib:temp Right set from storage ashen_lib:api CharArray[0]

# Check
scoreboard players set #IsPunc Ashen.Global.Temporary 0
data modify storage ashen_lib:temp punc set from storage ashen_lib:api Punctuation
execute if data storage ashen_lib:temp punc[0] run function ashen_lib:string/concat/core/check

# Exec
execute if score #IsPunc Ashen.Global.Temporary matches 1 run data modify storage ashen_lib:api Return append value ""
execute if score #IsPunc Ashen.Global.Temporary matches 0 run function ashen_lib:string/concat/core/concat with storage ashen_lib:api

# Reset
scoreboard players reset #IsPunc Ashen.Global.Temporary
data remove storage ashen_lib:temp Left
data remove storage ashen_lib:temp Right

# Loop
data remove storage ashen_lib:api CharArray[0]
execute if data storage ashen_lib:api CharArray[0] run function ashen_lib:string/concat/core/
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#> ashen_lib:string/concat/core/_index.d
# @private

#> Score Holder
# @within function ashen_lib:string/concat/core/**
#declare score_holder #IsPunc
19 changes: 19 additions & 0 deletions data/ashen_lib/functions/string/concat/core/check.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#> ashen_lib:string/concat/core/check
# @within function
# ashen_lib:string/concat/core/
# ashen_lib:string/concat/core/check

#> Private
# @private
#declare score_holder #Different

# Check
execute store result score #Different Ashen.Global.Temporary run data modify storage ashen_lib:temp punc[0] set from storage ashen_lib:api CharArray[0]
execute if score #Different Ashen.Global.Temporary matches 0 run scoreboard players set #IsPunc Ashen.Global.Temporary 1

# Reset
scoreboard players reset #Different Ashen.Global.Temporary

# Loop
data remove storage ashen_lib:temp punc[0]
execute if data storage ashen_lib:temp punc[0] run function ashen_lib:string/concat/core/check
4 changes: 4 additions & 0 deletions data/ashen_lib/functions/string/concat/core/concat.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#> ashen_lib:string/concat/core/concat
# @within function ashen_lib:string/concat/core/

$data modify storage ashen_lib:api Return[-1] set value "$(Left)$(Right)"

0 comments on commit 8debb2b

Please sign in to comment.