Skip to content

Restricting string length #657

Answered by cueckoo
cueckoo asked this question in Q&A
Jul 3, 2021 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

Original reply by @mpvl in cuelang/cue#657 (comment)

import "strings"

v: strings.MaxRunes(8) & strings.MinRunes(8)

There is a PR pending to add NumRunes too.

But you could make regex's variable:

#StrLen: {
    =~"^.{\(#n)}$"
   #n: int
}
#StrLen8: { #StrLen, #n: 8 }

Scalar values may have definition fields associated with them. This is a fairly new feature and some syntax has been proposed to make this more natural.

Replies: 2 comments 2 replies

Comment options

cueckoo
Jul 3, 2021
Collaborator Author

You must be logged in to vote
0 replies
Answer selected by cueckoo
Comment options

cueckoo
Jul 3, 2021
Collaborator Author

You must be logged in to vote
2 replies
@cueckoo
Comment options

cueckoo Jul 3, 2021
Collaborator Author

@cueckoo
Comment options

cueckoo Jul 3, 2021
Collaborator Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant