# std.zig.fmtId: conditionally escape primitives/\`\_\` · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/d8e7eda5f4a894fe8fec8c53f7bcc3d475dd55c9)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: d8e7eda5f4a894fe8fec8c53f7bcc3d475dd55c9

Requested commit: d8e7eda5f4a894fe8fec8c53f7bcc3d475dd55c9

Commit: d8e7eda5f4a894fe8fec8c53f7bcc3d475dd55c9

Tree: cb194249a7cdc1643283219bc6c327ad5b8363ac

Author: Carl Åstholm

Committer: Carl Åstholm

## Message

```
std.zig.fmtId: conditionally escape primitives/`_`

This is a breaking change.

This updates `std.zig.fmtId` to support conditionally escaping
primitives and the reserved `_` identifier via format specifiers:

- `{}`: escape invalid identifiers, identifiers that shadow primitives
  and the reserved `_` identifier.
- `{p}`: same as `{}`, but don't escape identifiers that
  shadow primitives.
- `{_}`: same as `{}`, but don't escape the reserved `_` identifier.
- `{p_}` or `{_p}`: only escape invalid identifiers.

(The idea is that `p`/`_` mean "allow primitives/underscores".)

Any other format specifiers will result in compile errors.

Additionally, `isValidId` now considers `_` a valid identifier. If this
distinction is important, consider combining existing uses of this
function with the new `isUnderscore` function.

```

## Parents

- [129de47a71b954b1118ce188f7032ad726491f53](https://git.cafe/gitcafe/zig/commit/129de47a71b954b1118ce188f7032ad726491f53?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/d8e7eda5f4a894fe8fec8c53f7bcc3d475dd55c9?format=markdown)
