BurntSushi / ucd-generate

A command line tool to generate Unicode tables as source code.
Apache License 2.0
95 stars 21 forks source link

Add --rust-enum option to general-category sub-command #20

Closed wezm closed 4 years ago

wezm commented 4 years ago

Adds a --rust-enum option to the general-category command.

The inclusive range change can be removed if you want. It was suggested when folks from work were reviewing my changes. I checked that it's supported by the MSRV.

Sample output:

// DO NOT EDIT THIS FILE. IT WAS AUTOMATICALLY GENERATED BY:
//
//  ucd-generate general-category --rust-enum /home/wmoore/Downloads/ucd-9
//
// ucd-generate is available on crates.io.

#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub enum GeneralCategory {
  ClosePunctuation, ConnectorPunctuation, Control, CurrencySymbol,
  DashPunctuation, DecimalNumber, EnclosingMark, FinalPunctuation, Format,
  InitialPunctuation, LetterNumber, LineSeparator, LowercaseLetter,
  MathSymbol, ModifierLetter, ModifierSymbol, NonspacingMark, OpenPunctuation,
  OtherLetter, OtherNumber, OtherPunctuation, OtherSymbol, ParagraphSeparator,
  PrivateUse, SpaceSeparator, SpacingMark, Surrogate, TitlecaseLetter,
  Unassigned, UppercaseLetter,
}

pub const GENERAL_CATEGORY: &'static [(u32, u32, GeneralCategory)] = &[
  (0, 31, GeneralCategory::Control),
  (32, 32, GeneralCategory::SpaceSeparator),
  (33, 35, GeneralCategory::OtherPunctuation),
  (36, 36, GeneralCategory::CurrencySymbol),
  (37, 39, GeneralCategory::OtherPunctuation),
  (40, 40, GeneralCategory::OpenPunctuation),
  ⋮
];
BurntSushi commented 4 years ago

I checked that it's supported by the MSRV.

For a dev tool like this, I don't care too much about MSRV. I do have one pinned in CI mostly out of habit and for good hygiene. But I'm happy to bump it whenever, but perhaps would like to go no newer than stable-2.

Also, for the future, it would help if commit messages could be styled in a fashion similar to the rest of commits. Usually I squash PRs down to one commit and I can rewrite the commit message in the GitHub UI, but when you have well organized commits (such as this PR), then I'm more inclined to avoid squashing and commit them as is. But then it becomes a bit more annoying to merge PRs.