CH04-L01 · applied

String size and Unicode

Measure text containing diacritics and an emoji in Unicode characters.

General CELRuns hereDocumented
What will I learn?

You can explain what size() counts for a string and why it is not a byte count.

Where will I try it?

Directly below, in the browser playground.

What do I do?

Run both modes, compare where their values come from, then complete the task.

Try CEL · browser pilot

Try both ways to supply values

Define local values inside one CEL expression, or provide variables as JSON input. Everything runs in your browser.

CEL pilot subset
One self-contained CEL expressioncel.bind() gives a local name to a value and returns the result of the final expression.

cel.bind()cel.bind() is an optional official extension. It is not part of the core CEL language and may not be enabled by every host application.

Tip: press Ctrl/⌘ + Enter to run.
Result

Press Run CEL to evaluate the active example.

Pilot scope: literals, explicit conversions, local cel.bind() variables, JSON variables, lists, maps, presence, collection macros, core string checks, time values, arithmetic, comparisons, logic, and the conditional operator.

What you will do

You will run the prepared expression in the playground above, change one input at a time, and explain the result. Start in CEL only, then repeat the same rule in CEL + JSON.

How it works

For strings, size() counts Unicode code points, not UTF-8 bytes. The text Žilina 👋 contains six letters, one space, and one emoji, so this example returns 8. This definition is stable across hosts even though a user-perceived character can sometimes contain multiple code points.

Read the prepared example

The CEL + JSON rule is:

text.size()

Its input is:

{
  "text": "Žilina 👋"
}

The CEL only tab contains the values and the rule in one expression. The enabled cel.bind() extension keeps each name local to its final argument.

Evaluation step by step

  1. CEL reads the value as one Unicode string.
  2. size() counts its Unicode code points.
  3. The result is the integer 8.

Your task

  1. Run both modes and confirm 8.
  2. Remove the emoji and run again.
  3. Try '👨‍👩‍👧‍👦'.size() and note that a visual symbol can use several code points.

Expected observation: Removing the emoji returns 7; the family emoji demonstrates the difference between code points and visual graphemes.

Common mistake

Do not use string size() as a byte limit for storage or networking. Byte length is a different measurement.

Show the explanation

The CEL string definition makes size() count Unicode code points.

Knowledge check

Why is the result not the UTF-8 byte length?

Key takeaway

Know what is being counted: string size is a code-point count, not a byte count.

Sources

  • CEL-DEV — official CEL overview.
  • CEL-LANG — official CEL language definition.
  • CEL-GO-BIND — official documentation for the optional cel.bind() extension used by the self-contained tab.