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

implement unicode safe api for String #1471

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

Conversation

Yu-zh
Copy link
Collaborator

@Yu-zh Yu-zh commented Jan 13, 2025

Part of #1452

Copy link

peter-jerry-ye-code-review bot commented Jan 13, 2025

‼️ This code review is generated by a bot. Please verify the content before trusting it.

Here are three observations and potential issues from the provided git diff output:

  1. Redundant Function Definitions:

    • In builtin/intrinsics.mbt, both String::get and String::unsafe_get are defined with the same implementation ("%string_get"). This redundancy might lead to confusion or maintenance issues. Consider whether unsafe_get should have a different implementation or if it should be removed entirely if it serves the same purpose as get.
  2. Potential Panic in code_point_at Function:

    • The code_point_at function in string/string.mbt has a loop that increments idx and num, but the else block after the loop assumes that num == index will always be true when the loop exits. However, if the loop exits early due to an invalid surrogate pair, num might not equal index, leading to a panic. This could be a logical error, and the condition should be carefully reviewed to ensure it behaves as expected in all cases.
  3. Inconsistent Documentation:

    • The documentation for code_unit_at and code_point_at in string/string.mbt mentions that these functions panic if the index is out of bounds. However, the unsafe_get function, which is used internally, does not have any bounds checking. This inconsistency could lead to confusion or misuse of the unsafe_get function, as users might assume it performs bounds checking like the higher-level functions. Consider adding clear documentation to unsafe_get to indicate that it does not perform bounds checking and should be used with caution.

These issues should be addressed to improve code clarity, maintainability, and correctness.

@coveralls
Copy link
Collaborator

coveralls commented Jan 13, 2025

Pull Request Test Coverage Report for Build 4744

Details

  • 0 of 26 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.4%) to 82.475%

Changes Missing Coverage Covered Lines Changed/Added Lines %
string/string.mbt 0 26 0.0%
Totals Coverage Status
Change from base Build 4739: -0.4%
Covered Lines: 4819
Relevant Lines: 5843

💛 - Coveralls

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