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 element length #2854

Merged
merged 20 commits into from
Sep 15, 2023
Merged

String element length #2854

merged 20 commits into from
Sep 15, 2023

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Mar 27, 2023

Fix #2851

@github-advanced-security
Copy link

You have successfully added a new CodeQL configuration /language:csharp. As part of the setup process, we have scanned this repository and found 2 existing alerts. Please check the repository Security tab to see all alerts.

@Jim8y
Copy link
Contributor Author

Jim8y commented Mar 27, 2023

@superboyiii Do you have any idea what is CodeQL, it was automatically added to my pr, is it a new feature of this repo you configured?

@Jim8y Jim8y changed the title String length in multiple different encode String length in multiple encode Mar 27, 2023
@roman-khimov
Copy link
Contributor

We have CodeQL enabled for NeoGo repo, it's a nice thing to have in general (another type of static analysis), even though we have some false positives from it.

@superboyiii
Copy link
Member

@superboyiii Do you have any idea what is CodeQL, it was automatically added to my pr, is it a new feature of this repo you configured?

I haven't tried CodeQL before, I have no authority to modify the config.
7570cec This is not your commit? 😹

@Jim8y
Copy link
Contributor Author

Jim8y commented Mar 27, 2023

My local commit does not contain that file, what a weird thing. Forget it, not a big issue.

@Jim8y
Copy link
Contributor Author

Jim8y commented Mar 27, 2023

LMAO, maybe it is me configured my forked repo or something, forget it.

@@ -222,5 +223,39 @@ private static string[] StringSplit([MaxLength(MaxInputLength)] string str, stri
StringSplitOptions options = removeEmptyEntries ? StringSplitOptions.RemoveEmptyEntries : StringSplitOptions.None;
return str.Split(separator, options);
}

[ContractMethod(CpuFee = 1 << 8)]
private static int StringByteLength([MaxLength(MaxInputLength)] string str)
Copy link
Member

Choose a reason for hiding this comment

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

It is same as OpCode.SIZE?

Copy link
Contributor Author

@Jim8y Jim8y Mar 29, 2023

Choose a reason for hiding this comment

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

It is same as OpCode.SIZE?

Exactly, just thought it would be better to make the naming style consistent.

Copy link
Member

Choose a reason for hiding this comment

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

It is same as OpCode.SIZE?

Exactly, just thought it would be better to make the naming style consistent.

Is not the same because this take in care about the unicode chars

Jim8y added 2 commits March 29, 2023 15:24
…g-length

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
private static int StringCharLength([MaxLength(MaxInputLength)] string str)
{
// return the length of the string in characters
// it should return 2 for "🦆" and 1 for "ã"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need it? It's tied to .NET-specific definition of Char and UTF-16 which is very niche. At the moment I just don't know how it could be implemented in Go. utf8.RuneCountInString works fine or StringElementLength, but StringCharLength looks very much C#/.NET specific and not very useful at the first glance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove this one then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@roman-khimov updated, may you please review again

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks OK, just one simple method.

@Jim8y
Copy link
Contributor Author

Jim8y commented Mar 31, 2023

@superboyiii also it would be awesome if you could kindly test the performance of this function to correctly and precisely set the gas fee

@Jim8y Jim8y changed the title String length in multiple encode String element length Apr 24, 2023
@Jim8y
Copy link
Contributor Author

Jim8y commented Aug 29, 2023

@shargon

@shargon
Copy link
Member

shargon commented Aug 31, 2023

@roman-khimov #2854 (comment) could you replicate the logic in Go now?

Copy link
Contributor

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

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

@roman-khimov #2854 (comment) could you replicate the logic in Go now?

I think so. Is this one for 3.6?

@shargon
Copy link
Member

shargon commented Sep 1, 2023

@roman-khimov #2854 (comment) could you replicate the logic in Go now?

I think so. Is this one for 3.6?

I think that it could be included

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.

Add a method to get the length of a String
5 participants