Misc.Utf8_lexeme(3)

πŸ’– NAME πŸ’–

okay so this is the Misc.Utf8_lexeme(3) page from the OCaml library manual, bestie. The official name line is Misc.Utf8_lexeme - no description. And like… that's genuinely it for the description. No cap. πŸ’€

🧚 Module 🧚

Module Misc.Utf8_lexeme β€” yes queen, that's the module we're talking about. πŸ’…

✨ Documentation ✨

Module Utf8_lexeme
 : sig end

🌸 type t 🌸

type t = string

Lowkey just a string, but make it fashion. πŸŽ€

🌈 normalize 🌈

val normalize : string -> (t, t) Result.t

Normalize the given UTF-8 encoded string. Invalid UTF-8 sequences results in a error and are replaced by U+FFFD. Identifier characters are put in NFC normalized form. Other Unicode characters are left unchanged. Slay. ✨

πŸŽ€ capitalize πŸŽ€

val capitalize : string -> (t, t) Result.t

Like normalize, but if the string starts with a lowercase identifier character, it is replaced by the corresponding uppercase character. Subsequent characters are not changed. Periodt. πŸ‘‘

πŸ¦‹ uncapitalize πŸ¦‹

val uncapitalize : string -> (t, t) Result.t

Like normalize, but if the string starts with an uppercase identifier character, it is replaced by the corresponding lowercase character. Subsequent characters are not changed. Cute. πŸŽ€

πŸ’œ is_capitalized πŸ’œ

val is_capitalized : t -> bool

Returns true if the given normalized string starts with an uppercase identifier character, false otherwise. May return wrong results if the string is not normalized. So like… iykyk. πŸ™ˆ

πŸ”₯ is_valid_identifier πŸ”₯

val is_valid_identifier : t -> bool

Check whether the given normalized string is a valid OCaml identifier:

  • -all characters are identifier characters
  • -it does not start with a digit or a single quote

That's the vibe check for identifiers. βœ…

🌸 is_lowercase 🌸

val is_lowercase : t -> bool

Returns true if the given normalized string only contains lowercase identifier character, false otherwise. May return wrong results if the string is not normalized. Again: iykyk, bestie. πŸ’–

🧚 type validation_result 🧚

type validation_result =
 | Valid
 | Invalid_character of Uchar.t
  (* Character not allowed
 *)
 | Invalid_beginning of Uchar.t
  (* Character not allowed as first char
 *)

So iconic: Valid means valid, Invalid_character of Uchar.t means character not allowed, and Invalid_beginning of Uchar.t means character not allowed as first char. The comments stay exactly as they are. πŸ’…

⭐ validate_identifier ⭐

val validate_identifier : ?with_dot:bool -> t -> validation_result

Like is_valid_identifier, but returns a more detailed error code. Dots can be allowed to extend support to path-like identifiers. So if you're doing path-like stuff, ?with_dot is your girl. 🫢

πŸ“ starts_like_a_valid_identifier πŸ“

val starts_like_a_valid_identifier : t -> bool

Checks whether the given normalized string starts with an identifier character other than a digit or a single quote. Subsequent characters are not checked. It's giving β€œjust the beginning, no full audit”. πŸ‘€


k bye bestie πŸ’… this iconic page was brought to you by OCamldoc, date 2026-06-22, for Misc.Utf8_lexeme(3). Mwah. πŸ’–

πŸ“¦ where this page comes from