Skip to content
Merged

. #9

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
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ scoreboard objectives add StringLib dummy
execute unless score #StringLib.Init StringLib matches 1 run function macroengine_string:zprivate/init

# Tellraw
execute if score #StringLib.ShowLoadMessage StringLib matches 1 run tellraw @a ["﹌ ",{"text":"StringLib >> ","color":"#99EAD6"},{"text":"Made by CMDred","hoverEvent":{"action":"show_text","value":[{"text":"YouTube: ","color":"dark_aqua"},{"text":"CMDred","color":"white"}]}},"\n﹌ ",{"text":"StringLib >> ","color":"#99EAD6"},"Get the latest updates: ",{"text":"Modrinth","color":"#5491F7","hoverEvent":{"action":"show_text","value":["Open page"]}},", ",{"text":"GitHub","color":"#5491F7","hoverEvent":{"action":"show_text","value":["Open page"]}}]
execute if score #StringLib.ShowLoadMessage StringLib matches 1 run tellraw @a ["﹌ ",{"text":"StringLib >> ","color":"#99EAD6"},{"text":"Made by CMDred","clickEvent":{"action":"open_url","value":"https://www.youtube.com/BluesProductionTeam"},"hoverEvent":{"action":"show_text","value":[{"text":"YouTube: ","color":"dark_aqua"},{"text":"CMDred","color":"white"}]}},"\n﹌ ",{"text":"StringLib >> ","color":"#99EAD6"},"Get the latest updates: ",{"text":"Modrinth","color":"#5491F7","clickEvent":{"action":"open_url","value":"https://modrinth.com/datapack/macroengine_string"},"hoverEvent":{"action":"show_text","value":["Open page"]}},", ",{"text":"GitHub","color":"#5491F7","clickEvent":{"action":"open_url","value":"https://github.com/runtoolkit/macroEngine"},"hoverEvent":{"action":"show_text","value":["Open page"]}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# No instance of the Separator was found - the whole String is the only element
data modify storage macroengine_string:output split append from storage macroengine_string:input split.String
data remove storage macroengine_string:temp data
return 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Append the remaining part of the string after the last separator instance
$data modify storage macroengine_string:temp data.Segment set string storage macroengine_string:input split.String $(Max)
data modify storage macroengine_string:output split append from storage macroengine_string:temp data.Segment
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Append the segment from Min to Max (skip empty unless KeepEmpty is 1b)
$data modify storage macroengine_string:temp data.Segment set string storage macroengine_string:input split.String $(Min) $(Max)
execute store result score #StringLib.SegmentLength StringLib run data get storage macroengine_string:temp data.Segment
execute unless score #StringLib.SegmentLength StringLib matches 0 run data modify storage macroengine_string:output split append from storage macroengine_string:temp data.Segment
execute if score #StringLib.SegmentLength StringLib matches 0 if score #StringLib.KeepEmpty StringLib matches 1 run data modify storage macroengine_string:output split append value ""

# This found instance is now consumed; stop once none are left
data remove storage macroengine_string:output find[0]
execute unless data storage macroengine_string:output find[0] run return 0

# Move Min to just after the separator we just split on, then jump Max to the next found index
scoreboard players operation #StringLib.NextMin StringLib = #StringLib.Max StringLib
scoreboard players operation #StringLib.NextMin StringLib += #StringLib.SeparatorLength StringLib
execute store result storage macroengine_string:temp data.Min int 1 run scoreboard players get #StringLib.NextMin StringLib
execute store result storage macroengine_string:temp data.Max int 1 store result score #StringLib.Max StringLib run data get storage macroengine_string:output find[0]

function macroengine_string:zprivate/split/main with storage macroengine_string:temp data
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Append the segment from Min to Max (skip empty unless KeepEmpty is 1b) — inserted at the front to preserve left-to-right order
$data modify storage macroengine_string:temp data.Segment set string storage macroengine_string:input split.String $(Min) $(Max)
execute store result score #StringLib.SegmentLength StringLib run data get storage macroengine_string:temp data.Segment
execute unless score #StringLib.SegmentLength StringLib matches 0 run data modify storage macroengine_string:output split prepend from storage macroengine_string:temp data.Segment
execute if score #StringLib.SegmentLength StringLib matches 0 if score #StringLib.KeepEmpty StringLib matches 1 run data modify storage macroengine_string:output split prepend value ""

# This found instance is now consumed; stop once none are left
data remove storage macroengine_string:output find[-1]
execute unless data storage macroengine_string:output find[-1] run return 0

# Move Max to just before the separator we just split on (i.e. Min of this segment), then jump Min to the previous found index + separator length
data modify storage macroengine_string:temp data.Max set from storage macroengine_string:temp data.Min
execute store result score #StringLib.Max StringLib run data get storage macroengine_string:temp data.Max
execute store result storage macroengine_string:temp data.Min int 1 store result score #StringLib.PrevIndex StringLib run data get storage macroengine_string:output find[-1]
scoreboard players operation #StringLib.PrevIndex StringLib += #StringLib.SeparatorLength StringLib
execute store result storage macroengine_string:temp data.Min int 1 run scoreboard players get #StringLib.PrevIndex StringLib

function macroengine_string:zprivate/split/reversed/main with storage macroengine_string:temp data
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Clean up leftover intermediate keys from the split process (KeepEmpty/Segment/Min/Max are re-derived each run, so nothing here is needed after this point)
data remove storage macroengine_string:temp data.Segment
data remove storage macroengine_string:temp data.Min
data remove storage macroengine_string:temp data.Max
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Peel off the first character and append it as its own element
data modify storage macroengine_string:temp data.Char set string storage macroengine_string:temp data.Remaining 0 1
data modify storage macroengine_string:output split append from storage macroengine_string:temp data.Char

# Next loop
execute if score #StringLib.CharsLeft StringLib matches 1 run return 0
scoreboard players remove #StringLib.CharsLeft StringLib 1
data modify storage macroengine_string:temp data.Remaining set string storage macroengine_string:temp data.Remaining 1
function macroengine_string:zprivate/split/split_chars/loop
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Split every character of the String into its own list element
execute store result score #StringLib.CharsLeft StringLib run data get storage macroengine_string:input split.String
data modify storage macroengine_string:temp data.Remaining set from storage macroengine_string:input split.String
function macroengine_string:zprivate/split/split_chars/loop
data remove storage macroengine_string:temp data
return run execute if data storage macroengine_string:output split[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Convert current character to uppercase (& handle a character having 2 possible outputs)
data remove storage macroengine_string:temp data.List
$data modify storage macroengine_string:temp data.List append from storage macroengine_string:zprivate data.CharMap.Fast[{u:"$(Char)"}].l
data modify storage macroengine_string:temp data.CharList append from storage macroengine_string:temp data.List[0]
execute unless data storage macroengine_string:temp data.List run data modify storage macroengine_string:temp data.CharList append from storage macroengine_string:temp data.Char

# Next loop
execute if score #StringLib.CharsLeft StringLib matches 1 run return 0
scoreboard players remove #StringLib.CharsLeft StringLib 1
data modify storage macroengine_string:temp data.Input set string storage macroengine_string:temp data.Input 1
data modify storage macroengine_string:temp data.Char set string storage macroengine_string:temp data.Input 0 1
function macroengine_string:zprivate/to_lowercase/main_fast with storage macroengine_string:temp data
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Convert current character to uppercase (& handle a character having 2 possible outputs)
data remove storage macroengine_string:temp data.List
$data modify storage macroengine_string:temp data.List append from storage macroengine_string:zprivate data.CharMap.Full[{u:"$(Char)"}].l
data modify storage macroengine_string:temp data.CharList append from storage macroengine_string:temp data.List[0]
execute unless data storage macroengine_string:temp data.List run data modify storage macroengine_string:temp data.CharList append from storage macroengine_string:temp data.Char

# Next loop
execute if score #StringLib.CharsLeft StringLib matches 1 run return 0
scoreboard players remove #StringLib.CharsLeft StringLib 1
data modify storage macroengine_string:temp data.Input set string storage macroengine_string:temp data.Input 1
data modify storage macroengine_string:temp data.Char set string storage macroengine_string:temp data.Input 0 1
function macroengine_string:zprivate/to_lowercase/main_full with storage macroengine_string:temp data
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Convert current character to uppercase (& handle a character having 2 possible outputs)
data remove storage macroengine_string:temp data.List
$data modify storage macroengine_string:temp data.List append from storage macroengine_string:zprivate data.CharMap.Fast[{l:"$(Char)"}].u
data modify storage macroengine_string:temp data.CharList append from storage macroengine_string:temp data.List[0]
execute unless data storage macroengine_string:temp data.List run data modify storage macroengine_string:temp data.CharList append from storage macroengine_string:temp data.Char

# Next loop
execute if score #StringLib.CharsLeft StringLib matches 1 run return 0
scoreboard players remove #StringLib.CharsLeft StringLib 1
data modify storage macroengine_string:temp data.Input set string storage macroengine_string:temp data.Input 1
data modify storage macroengine_string:temp data.Char set string storage macroengine_string:temp data.Input 0 1
function macroengine_string:zprivate/to_uppercase/main_fast with storage macroengine_string:temp data
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Convert current character to uppercase (& handle a character having 2 possible outputs)
data remove storage macroengine_string:temp data.List
$data modify storage macroengine_string:temp data.List append from storage macroengine_string:zprivate data.CharMap.Full[{l:"$(Char)"}].u
data modify storage macroengine_string:temp data.CharList append from storage macroengine_string:temp data.List[0]
execute unless data storage macroengine_string:temp data.List run data modify storage macroengine_string:temp data.CharList append from storage macroengine_string:temp data.Char

# Next loop
execute if score #StringLib.CharsLeft StringLib matches 1 run return 0
scoreboard players remove #StringLib.CharsLeft StringLib 1
data modify storage macroengine_string:temp data.Input set string storage macroengine_string:temp data.Input 1
data modify storage macroengine_string:temp data.Char set string storage macroengine_string:temp data.Input 0 1
function macroengine_string:zprivate/to_uppercase/main_full with storage macroengine_string:temp data
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ scoreboard objectives add StringLib dummy
execute unless score #StringLib.Init StringLib matches 1 run function macroengine_string:zprivate/init

# Tellraw
execute if score #StringLib.ShowLoadMessage StringLib matches 1 run tellraw @a ["﹌ ",{"text":"StringLib >> ","color":"#99EAD6"},{"text":"Made by CMDred","hover_event":{"action":"show_text","value":[{"text":"YouTube: ","color":"dark_aqua"},{"text":"CMDred","color":"white"}]}},"\n﹌ ",{"text":"StringLib >> ","color":"#99EAD6"},"Get the latest updates: ",{"text":"Modrinth","color":"#5491F7","hover_event":{"action":"show_text","value":["Open page"]}},", ",{"text":"GitHub","color":"#5491F7","hover_event":{"action":"show_text","value":["Open page"]}}]
execute if score #StringLib.ShowLoadMessage StringLib matches 1 run tellraw @a ["﹌ ",{"text":"StringLib >> ","color":"#99EAD6"},{"text":"Made by CMDred","click_event":{"action":"open_url","url":"https://www.youtube.com/BluesProductionTeam"},"hover_event":{"action":"show_text","value":[{"text":"YouTube: ","color":"dark_aqua"},{"text":"CMDred","color":"white"}]}},"\n﹌ ",{"text":"StringLib >> ","color":"#99EAD6"},"Get the latest updates: ",{"text":"Modrinth","color":"#5491F7","click_event":{"action":"open_url","url":"https://modrinth.com/datapack/macroengine_string"},"hover_event":{"action":"show_text","value":["Open page"]}},", ",{"text":"GitHub","color":"#5491F7","click_event":{"action":"open_url","url":"https://github.com/runtoolkit/macroEngine"},"hover_event":{"action":"show_text","value":["Open page"]}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# No instance of the Separator was found - the whole String is the only element
data modify storage macroengine_string:output split append from storage macroengine_string:input split.String
data remove storage macroengine_string:temp data
return 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Append the remaining part of the string after the last separator instance
$data modify storage macroengine_string:temp data.Segment set string storage macroengine_string:input split.String $(Max)
data modify storage macroengine_string:output split append from storage macroengine_string:temp data.Segment
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Append the segment from Min to Max (skip empty unless KeepEmpty is 1b)
$data modify storage macroengine_string:temp data.Segment set string storage macroengine_string:input split.String $(Min) $(Max)
execute store result score #StringLib.SegmentLength StringLib run data get storage macroengine_string:temp data.Segment
execute unless score #StringLib.SegmentLength StringLib matches 0 run data modify storage macroengine_string:output split append from storage macroengine_string:temp data.Segment
execute if score #StringLib.SegmentLength StringLib matches 0 if score #StringLib.KeepEmpty StringLib matches 1 run data modify storage macroengine_string:output split append value ""

# This found instance is now consumed; stop once none are left
data remove storage macroengine_string:output find[0]
execute unless data storage macroengine_string:output find[0] run return 0

# Move Min to just after the separator we just split on, then jump Max to the next found index
scoreboard players operation #StringLib.NextMin StringLib = #StringLib.Max StringLib
scoreboard players operation #StringLib.NextMin StringLib += #StringLib.SeparatorLength StringLib
execute store result storage macroengine_string:temp data.Min int 1 run scoreboard players get #StringLib.NextMin StringLib
execute store result storage macroengine_string:temp data.Max int 1 store result score #StringLib.Max StringLib run data get storage macroengine_string:output find[0]

function macroengine_string:zprivate/split/main with storage macroengine_string:temp data
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Append the segment from Min to Max (skip empty unless KeepEmpty is 1b) — inserted at the front to preserve left-to-right order
$data modify storage macroengine_string:temp data.Segment set string storage macroengine_string:input split.String $(Min) $(Max)
execute store result score #StringLib.SegmentLength StringLib run data get storage macroengine_string:temp data.Segment
execute unless score #StringLib.SegmentLength StringLib matches 0 run data modify storage macroengine_string:output split prepend from storage macroengine_string:temp data.Segment
execute if score #StringLib.SegmentLength StringLib matches 0 if score #StringLib.KeepEmpty StringLib matches 1 run data modify storage macroengine_string:output split prepend value ""

# This found instance is now consumed; stop once none are left
data remove storage macroengine_string:output find[-1]
execute unless data storage macroengine_string:output find[-1] run return 0

# Move Max to just before the separator we just split on (i.e. Min of this segment), then jump Min to the previous found index + separator length
data modify storage macroengine_string:temp data.Max set from storage macroengine_string:temp data.Min
execute store result score #StringLib.Max StringLib run data get storage macroengine_string:temp data.Max
execute store result storage macroengine_string:temp data.Min int 1 store result score #StringLib.PrevIndex StringLib run data get storage macroengine_string:output find[-1]
scoreboard players operation #StringLib.PrevIndex StringLib += #StringLib.SeparatorLength StringLib
execute store result storage macroengine_string:temp data.Min int 1 run scoreboard players get #StringLib.PrevIndex StringLib

function macroengine_string:zprivate/split/reversed/main with storage macroengine_string:temp data
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Clean up leftover intermediate keys from the split process (KeepEmpty/Segment/Min/Max are re-derived each run, so nothing here is needed after this point)
data remove storage macroengine_string:temp data.Segment
data remove storage macroengine_string:temp data.Min
data remove storage macroengine_string:temp data.Max
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Peel off the first character and append it as its own element
data modify storage macroengine_string:temp data.Char set string storage macroengine_string:temp data.Remaining 0 1
data modify storage macroengine_string:output split append from storage macroengine_string:temp data.Char

# Next loop
execute if score #StringLib.CharsLeft StringLib matches 1 run return 0
scoreboard players remove #StringLib.CharsLeft StringLib 1
data modify storage macroengine_string:temp data.Remaining set string storage macroengine_string:temp data.Remaining 1
function macroengine_string:zprivate/split/split_chars/loop
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Split every character of the String into its own list element
execute store result score #StringLib.CharsLeft StringLib run data get storage macroengine_string:input split.String
data modify storage macroengine_string:temp data.Remaining set from storage macroengine_string:input split.String
function macroengine_string:zprivate/split/split_chars/loop
data remove storage macroengine_string:temp data
return run execute if data storage macroengine_string:output split[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Convert current character to uppercase (& handle a character having 2 possible outputs)
data remove storage macroengine_string:temp data.List
$data modify storage macroengine_string:temp data.List append from storage macroengine_string:zprivate data.CharMap.Fast[{u:"$(Char)"}].l
data modify storage macroengine_string:temp data.CharList append from storage macroengine_string:temp data.List[0]
execute unless data storage macroengine_string:temp data.List run data modify storage macroengine_string:temp data.CharList append from storage macroengine_string:temp data.Char

# Next loop
execute if score #StringLib.CharsLeft StringLib matches 1 run return 0
scoreboard players remove #StringLib.CharsLeft StringLib 1
data modify storage macroengine_string:temp data.Input set string storage macroengine_string:temp data.Input 1
data modify storage macroengine_string:temp data.Char set string storage macroengine_string:temp data.Input 0 1
function macroengine_string:zprivate/to_lowercase/main_fast with storage macroengine_string:temp data
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Convert current character to uppercase (& handle a character having 2 possible outputs)
data remove storage macroengine_string:temp data.List
$data modify storage macroengine_string:temp data.List append from storage macroengine_string:zprivate data.CharMap.Full[{u:"$(Char)"}].l
data modify storage macroengine_string:temp data.CharList append from storage macroengine_string:temp data.List[0]
execute unless data storage macroengine_string:temp data.List run data modify storage macroengine_string:temp data.CharList append from storage macroengine_string:temp data.Char

# Next loop
execute if score #StringLib.CharsLeft StringLib matches 1 run return 0
scoreboard players remove #StringLib.CharsLeft StringLib 1
data modify storage macroengine_string:temp data.Input set string storage macroengine_string:temp data.Input 1
data modify storage macroengine_string:temp data.Char set string storage macroengine_string:temp data.Input 0 1
function macroengine_string:zprivate/to_lowercase/main_full with storage macroengine_string:temp data
Loading