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

String: Add .is-empty and .length properties #7192

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

Conversation

task-jp
Copy link
Contributor

@task-jp task-jp commented Dec 21, 2024

Introduce two new methods for string properties in .slint:

  • .is_empty(): Checks if a string is empty.
  • .length(): Retrieves the length of the string.

These additions enhance functionality and improve convenience when working with string properties.

@task-jp task-jp force-pushed the string_length branch 2 times, most recently from 1a94a2f to aea12f3 Compare December 21, 2024 16:50
@ogoffart
Copy link
Member

Thanks a lot for the PR.
Code looks good. One thing missing are the docs.

What is the usecase for this?
I think is-empty make sense (even though it can be done with == "")
But I'm wondering about length, because it is not well defined. Currently it is utf8 bytes. But what can one do with this info? Perhaps one want the number of codepoints? Or does one want to get the size in pixel depending on the font?
Given that, I don't feel so good about adding this function.

(I also wonder if it shouldn't be a property instead of a function, like the one on model/array)

@task-jp
Copy link
Contributor Author

task-jp commented Dec 23, 2024

Thanks for your comment.

Code looks good. One thing missing are the docs.

How can I generate the docs like https://docs.slint.dev/latest/docs/slint/reference/primitive-types/#images ?

I've tried https://github.com/slint-ui/slint/blob/master/docs/development.md#documentation but it seems that only rust documentation is generated.

What is the usecase for this?

For length(), I wanted it to calculate password length in LineEdit.

Perhaps one want the number of codepoints?

Your are right. I will figure out how it would be.

(I also wonder if it shouldn't be a property instead of a function, like the one on model/array)

I thought so, then I found that is-float() was implemented as a function. I will check model/array and try to make them as properties.

Introduce two new properties for string in .slint:
- .is-empty: Checks if a string is empty.
- .length: Retrieves the number of grapheme clusters
  https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries

These additions enhance functionality and improve convenience when working with string properties.
@task-jp
Copy link
Contributor Author

task-jp commented Dec 24, 2024

I read https://github.com/slint-ui/slint/blob/master/docs/astro/README.md and was able to build the slintdoc.

@task-jp task-jp changed the title String: Add .is_empty() and .length() Methods String: Add .is-empty and .length properties Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants