diff src/utils.cc @ 4143:62afb31c1f85

[project @ 2002-11-01 17:27:38 by jwe]
author jwe
date Fri, 01 Nov 2002 17:27:38 +0000
parents e865976c2084
children 6b96ce9f5743
line wrap: on
line diff
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -79,6 +79,27 @@
 // Top level context (?)
 extern jmp_buf toplevel;
 
+// Return TRUE if S is a valid identifier.
+
+bool
+valid_identifier (const char *s)
+{
+  if (! s || ! (isalnum (*s) || *s == '_'))
+     return false;
+
+  while (*++s != '\0')
+    if (! (isalnum (*s) || *s == '_'))
+      return false;
+
+  return true;
+}
+
+bool
+valid_identifier (const std::string& s)
+{
+  return valid_identifier (s.c_str ());
+}
+
 // Return to the main command loop in octave.cc.
 
 void