aboutsummaryrefslogtreecommitdiff
path: root/src/utilities.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-05-15 23:44:53 -0700
committerFuwn <[email protected]>2022-05-15 23:44:53 -0700
commit242b0b9591fa4fd5f8b4a45ec4c179f451c62c14 (patch)
tree6dcc82c1e87725224bc3dcd22c974ab0775f4c7f /src/utilities.rs
parentdocs(license): add license for vergen (diff)
downloadchorus-main.tar.xz
chorus-main.zip
feat: initial development releaseHEADmain
Diffstat (limited to 'src/utilities.rs')
-rw-r--r--src/utilities.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/utilities.rs b/src/utilities.rs
new file mode 100644
index 0000000..e5b3c3c
--- /dev/null
+++ b/src/utilities.rs
@@ -0,0 +1,43 @@
+// This file is part of Chorus <https://github.com/Fuwn/chorus>.
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 3.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// Copyright (C) 2022-2022 Fuwn <[email protected]>
+// SPDX-License-Identifier: GPL-3.0-only
+
+use anyhow::anyhow;
+use unicode_xid::UnicodeXID;
+
+/// Check if a string is a valid Unicode XID identifier
+pub fn is_unicode_xid(input: &str) -> anyhow::Result<()> {
+ let mut input_scroller = input.chars();
+
+ if !UnicodeXID::is_xid_start(input_scroller.next().unwrap()) {
+ return Err(anyhow!(
+ "identifier \"{}\" is not valid unicode xid identifier",
+ input
+ ));
+ }
+
+ for character in input_scroller {
+ if !UnicodeXID::is_xid_continue(character) {
+ return Err(anyhow!(
+ "identifier \"{}\" is not valid unicode xid identifier",
+ input
+ ));
+ }
+ }
+
+ Ok(())
+}