Skip to content
New issue

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

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

Already on GitHub? # to your account

Add max_rune_size and min_rune_size annotations to validate Chinese strings. #35

Merged
merged 7 commits into from
Feb 8, 2025

Conversation

wangliyue2009
Copy link
Contributor

Add max_rune_size and min_rune_size annotations to support length validation of Chinese strings.

thrift

struct Example {
1: string MaxRuneString (vt.max_rune_size = "10")
2: string MinRuneString (vt.min_rune_size = "10")
3: map<string, string> KeyValues2 (vt.key.max_rune_size = "10" vt.key.min_rune_size = "10")
}

*_validator.go

func (p *Example) IsValid() error {
	if len([]rune(p.MaxRuneString)) > int(10) {
		return fmt.Errorf("field MaxRuneString max_rune_size rule failed, current value: %d", len([]rune(p.MaxRuneString)))
	}
	if len([]rune(p.MinRuneString)) < int(10) {
		return fmt.Errorf("field MinRuneString min_rune_size rule failed, current value: %d", len([]rune(p.MinRuneString)))
	}
	for k := range p.KeyValues {
		if len([]rune(k)) > int(10) {
			return fmt.Errorf("field k max_rune_size rule failed, current value: %d", len([]rune(k)))
		}
		if len([]rune(k)) < int(10) {
			return fmt.Errorf("field k min_rune_size rule failed, current value: %d", len([]rune(k)))
		}
	}
	return nil
}

@wangliyue2009 wangliyue2009 requested review from a team as code owners February 8, 2025 06:03
@CLAassistant
Copy link

CLAassistant commented Feb 8, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ HeyJavaBean
❌ wangly2009
You have signed the CLA already but the status is still pending? Let us recheck it.

HeyJavaBean
HeyJavaBean previously approved these changes Feb 8, 2025
@HeyJavaBean HeyJavaBean merged commit 4a18033 into cloudwego:main Feb 8, 2025
3 of 4 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants