Added a function to check whether a (UTF-8) string is a valid token.
authorPeter Verthez <Peter.Verthez@advalvas.be>
Sun, 22 Sep 2002 18:44:14 +0000 (18:44 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Sun, 22 Sep 2002 18:44:14 +0000 (18:44 +0000)
gedcom/gedcom_1byte.lex

index 938a97c476ed63b396be602ae07d56a03ec298e0..05cda4038bf4768d0dbca48a9cfd506c314e114f 100644 (file)
@@ -221,6 +221,39 @@ ACTION_BEFORE_REGEXPS
 #define LEX_SECTION 3  /* include only a specific part of the following file */
 #include "gedcom_lex_common.c"
 
+int gedcom_check_token(const char* str, ParseState state, int check_token)
+{
+  int result = 0;
+  int token;
+  YY_BUFFER_STATE buffer;
+
+  yy_delete_buffer(YY_CURRENT_BUFFER);
+  buffer = yy_scan_string(str);
+
+  if (state == STATE_NORMAL)
+    BEGIN(NORMAL);
+  else if (state == STATE_INITIAL)
+    BEGIN(INITIAL);
+  else if (state == STATE_EXPECT_TAG)
+    BEGIN(EXPECT_TAG);
+
+  /* Input is UTF-8 coming from the application, so bypass iconv */
+  dummy_conv = 1;
+  token = yylex();
+  if (token != check_token)
+    result = 1;
+  
+  if (token != 0) {
+    token = yylex();
+    if (token != 0)
+      result = 1;
+  }
+  dummy_conv = 0;
+  
+  yy_delete_buffer(buffer);
+  return result;
+}
+
 #ifdef LEXER_TEST
 int gedcom_lex()
 {