-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename generators for clarity Signed-off-by: James Sturtevant <jsturtevant@gmail.com> * Move interface generator to own module Signed-off-by: James Sturtevant <jsturtevant@gmail.com> * Move function generator to own module Signed-off-by: James Sturtevant <jsturtevant@gmail.com> * Move Ident code to own file Signed-off-by: James Sturtevant <jsturtevant@gmail.com> * Move World generator code to own file Signed-off-by: James Sturtevant <jsturtevant@gmail.com> * Add some comments and alittle clean up Signed-off-by: James Sturtevant <jsturtevant@gmail.com> --------- Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
- Loading branch information
1 parent
c2e7892
commit 9b91987
Showing
5 changed files
with
3,604 additions
and
3,557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
use heck::{ToLowerCamelCase, ToUpperCamelCase}; | ||
|
||
pub(crate) trait ToCSharpIdent: ToOwned { | ||
fn csharp_keywords() -> Vec<&'static str>; | ||
fn to_csharp_ident(&self) -> Self::Owned; | ||
fn to_csharp_ident_upper(&self) -> Self::Owned; | ||
} | ||
|
||
impl ToCSharpIdent for str { | ||
// Source: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ | ||
fn csharp_keywords() -> Vec<&'static str> { | ||
vec![ | ||
"abstract", | ||
"as", | ||
"base", | ||
"bool", | ||
"break", | ||
"byte", | ||
"case", | ||
"catch", | ||
"char", | ||
"checked", | ||
"class", | ||
"const", | ||
"continue", | ||
"decimal", | ||
"default", | ||
"delegate", | ||
"do", | ||
"double", | ||
"else", | ||
"enum", | ||
"event", | ||
"explicit", | ||
"extern", | ||
"false", | ||
"finally", | ||
"fixed", | ||
"float", | ||
"for", | ||
"foreach", | ||
"goto", | ||
"if", | ||
"implicit", | ||
"in", | ||
"int", | ||
"interface", | ||
"internal", | ||
"is", | ||
"lock", | ||
"long", | ||
"namespace", | ||
"new", | ||
"null", | ||
"object", | ||
"operator", | ||
"out", | ||
"override", | ||
"params", | ||
"private", | ||
"protected", | ||
"public", | ||
"readonly", | ||
"ref", | ||
"return", | ||
"sbyte", | ||
"sealed", | ||
"short", | ||
"sizeof", | ||
"stackalloc", | ||
"static", | ||
"string", | ||
"struct", | ||
"switch", | ||
"this", | ||
"throw", | ||
"true", | ||
"try", | ||
"typeof", | ||
"uint", | ||
"ulong", | ||
"unchecked", | ||
"unsafe", | ||
"ushort", | ||
"using", | ||
"virtual", | ||
"void", | ||
"volatile", | ||
"while", | ||
] | ||
} | ||
|
||
fn to_csharp_ident(&self) -> String { | ||
// Escape C# keywords | ||
if Self::csharp_keywords().contains(&self) { | ||
format!("@{}", self) | ||
} else { | ||
self.to_lower_camel_case() | ||
} | ||
} | ||
|
||
fn to_csharp_ident_upper(&self) -> String { | ||
// Escape C# keywords | ||
if Self::csharp_keywords().contains(&self) { | ||
format!("@{}", self) | ||
} else { | ||
self.to_upper_camel_case() | ||
} | ||
} | ||
} |
Oops, something went wrong.