[geany/geany] 67f3ad: read: Move logic for getting a previous character into a read function

Colomban Wendling git-noreply at xxxxx
Thu Feb 11 14:36:04 UTC 2016


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Sun, 24 Jan 2016 16:25:12 UTC
Commit:      67f3add7c7bed2b86769c9b86f2d6178b6daef6a
             https://github.com/geany/geany/commit/67f3add7c7bed2b86769c9b86f2d6178b6daef6a

Log Message:
-----------
read: Move logic for getting a previous character into a read function

This ties related logic together, making it less of a hack and easier
to maintain, as well as accessible by all parsers if needed.


Modified Paths:
--------------
    tagmanager/ctags/get.c
    tagmanager/ctags/read.c
    tagmanager/ctags/read.h

Modified: tagmanager/ctags/get.c
5 lines changed, 1 insertions(+), 4 deletions(-)
===================================================================
@@ -801,10 +801,7 @@ extern int cppGetc (void)
 					 * 	"xxx(raw)xxx";
 					 *
 					 * which is perfectly valid (yet probably very unlikely). */
-					const unsigned char *base = (unsigned char *) vStringValue (File.line);
-					int prev = '\n';
-					if (File.currentLine - File.ungetchIdx - 2 >= base)
-						prev = (int) *(File.currentLine - File.ungetchIdx - 2);
+					int prev = fileGetNthPrevC (1, 0);
 
 					if (! isident (prev))
 					{


Modified: tagmanager/ctags/read.c
12 lines changed, 12 insertions(+), 0 deletions(-)
===================================================================
@@ -501,6 +501,18 @@ extern int fileGetc (void)
     return c;
 }
 
+/* returns the nth previous character (0 meaning current), or def if nth cannot
+ * be accessed.  Note that this can't access previous line data. */
+extern int fileGetNthPrevC (unsigned int nth, int def)
+{
+	const unsigned char *base = (unsigned char *) vStringValue (File.line);
+
+	if (File.currentLine - File.ungetchIdx - 1 - nth >= base)
+		return (int) *(File.currentLine - File.ungetchIdx - 1 - nth);
+	else
+		return def;
+}
+
 extern int fileSkipToCharacter (int c)
 {
 	int d;


Modified: tagmanager/ctags/read.h
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -102,6 +102,7 @@ extern boolean fileOpen (const char *const fileName, const langType language);
 extern boolean fileEOF (void);
 extern void fileClose (void);
 extern int fileGetc (void);
+extern int fileGetNthPrevC (unsigned int nth, int def);
 extern int fileSkipToCharacter (int c);
 extern void fileUngetc (int c);
 extern const unsigned char *fileReadLine (void);



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list