Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: add a new bs.string module #283

Open
wants to merge 45 commits into
base: master
Choose a base branch
from

Conversation

aure31
Copy link

@aure31 aure31 commented Nov 30, 2024

Tasks to do before merging

  • I accept to publish my contribution under MPL v2 License
  • My pull request is linked to an existing issue
  • I have added my contribution to the changelog
  • If my pull request is a new or modify an existing feature:
    • I have documented my contribution (/docs)
    • I have added or updated the header of the features' root function I contribute
    • I have tested my contribution

and implementation of the `index_of` and `lenth` feature
@aure31
Copy link
Author

aure31 commented Nov 30, 2024

close #191

@theogiraudet theogiraudet added the ✨ Module New modules label Nov 30, 2024
@theogiraudet theogiraudet added this to the 3.0.0 milestone Nov 30, 2024
@theogiraudet theogiraudet linked an issue Nov 30, 2024 that may be closed by this pull request
3 tasks
Copy link
Member

@aksiome aksiome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey really quick review before this gets too big. I have'nt reviewed everything but it's a start

Copy link
Member

@aksiome aksiome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok i'm really nitpicking here, i mainly reviewed the style and not the logic. For the logic I'll need more time to run the tests and all. Also there are some remaining say and tellraw, i'm sure it's because it's not completly finished and ready for the last review, but i commented some of them (not all). A small cleanup cannot hurt i guess 👍

@@ -0,0 +1,100 @@
# 🔠 String

**`#bs.string:help`**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to have a small description, a banner image, and a quote for our module. Nothing is mandatory except the description, but it's better with all of them

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how you find the image for the module with a black and white variant

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either have a png with transparent background, or make 2 versions. If you don't really feel like doing some image design we'll try to do it (either Theo or me)

@aksiome aksiome changed the title Add a new bs.string module ✨ feat: add a new bs.string module Feb 26, 2025
@aksiome aksiome marked this pull request as ready for review March 2, 2025 10:26
Copy link
Member

@aksiome aksiome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Globally i think we should avoid mixing storage and macro. This is because it's really hard to tell if some parameters are to be used dynamically or not. For example occurence may be used with a constant value but some people might want to use it dynamically and it adds extra complexity. I think we should only use storage for the whole module. Also some tests are failing, and i think some function could be changed a bit. Here are my propositions:

  • find should be renamed find_all (still returns a list) and we should have a simple find that returns only the first occurence as an int from the function. This mean that the command can easily be used with if function.
  • insert can be reworked easily into something like replace_range / substr_replace which does the same and more with a similar implementation (see the details after)

# 🔠 String

**`#bs.string:help`**

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • In the documentation a lot of sentences are missing their . at the end.
  • Verbs should be imperative. For example in uppercase/lowercase, Converts should be Convert instead.
  • In multiple examples the description does not have an uppercase at the start of the sentence.
  • Functions should be sorted in alphabetical order.
  • Storage inputs/outputs should use treeview (see other modules like block) if more than 1, and examples should also work this way. For example in replace:
    # avoid
    data modify storage bs:in string.replace.str set value "hello world"
    data modify storage bs:in string.replace.old set value "world"
    data modify storage bs:in string.replace.new set value "minecraft"
    
    # use instead to encourage people to use only the base path (string.replace) to override the whole compound and avoid unintended side effects when multiple pack use bookshelf
    data modify storage bs:in string.replace set value {str: "hello world", old: "world", new: "minecraaft"}

**Strorage `bs:out string.replace`**: {nbt}`string` The replaced string
```

_replace world by minecraft:_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

world and minecraft missing `` => world and minecraft

data modify storage bs:in string.replace.old set value "world"
data modify storage bs:in string.replace.new set value "minecraft"

function #bs.string:replace {type:'fast'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type macro should not be here

scoreboard objectives remove bs.out
scoreboard objectives remove bs.ctx

#data remove storage bs:in string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove both input and outputs when unloading the module also the const score

scoreboard objectives add bs.ctx dummy [{"text":"BS ","color":"dark_gray"},{"text":"Ctx","color":"aqua"}]
scoreboard objectives add bs.const dummy [{"text":"BS ","color":"dark_gray"},{"text":"Const","color":"aqua"}]

#set constant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really consistent with other comments, we should always add a space after #. Also not sure this one is really needed since the code is self explanatory. We don't really have conventions for comments but i think it's best to be consistent across a module (like for example if you use uppercase at the start of comments use it everywhere)

# For more details, refer to the MPL v2.0.
# ------------------------------------------------------------------------------------------------------------

data modify storage bs:out string.find append from storage bs:ctx x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said after in find avoid using x and use the score instead

data modify storage bs:ctx _.ltr set string storage bs:ctx _.test -1
execute store success score #t bs.ctx run data modify storage bs:ctx _.test set from storage bs:in string.find.needle

data modify storage bs:ctx z set from storage bs:ctx y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed directly use y directly in match_pattern instead

#
# For more details, refer to the MPL v2.0.
# ------------------------------------------------------------------------------------------------------------

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for normal/skip

# - Any modifications must be documented and disclosed under the same license
#
# For more details, refer to the MPL v2.0.
# ------------------------------------------------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing new line. Also im lazy and i think a lot of code is shared with find, so i'll just say everything for find applies here

# For more details, refer to the MPL v2.0.
# ------------------------------------------------------------------------------------------------------------

#reset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment style. Also im lazy so i'll just say that everything from find applies here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Module New modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bs.string: A module to manage strings
3 participants