From 2bcd419fe75c77938436f78a61e37457b0e267c3 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Thu, 5 Oct 2017 15:14:05 +0900 Subject: [PATCH] main: trim whitespace prefix from tag name Close #1141 Original issue: [yamato@x201]~/var/ctags-github% cat /tmp/foo.html cat /tmp/foo.html

ABC

[yamato@x201]~/var/ctags-github% ./ctags /tmp/foo.html ./ctags /tmp/foo.html [yamato@x201]~/var/ctags-github% cat tags cat tags ABC /tmp/foo.html /^

ABC<\/h1>$/;" h !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ !_TAG_PROGRAM_AUTHOR Universal Ctags Team // !_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/ !_TAG_PROGRAM_URL https://ctags.io/ /official site/ !_TAG_PROGRAM_VERSION 0.0.0 /25bad34/ Look at the whiespace before ABC. If a tag name is started with a whitespace, it is printed in tags file before pseudo tags. I guess this behavior make client tools get into crazy. This patch trims whitespace characters at the head of tag name. trimPrefixedWhitespaces() function is much simpflied by @codebrainz. Signed-off-by: Masatake YAMATO --- .../whitespace-prefixed.html.d/expected.tags | 1 + .../whitespace-prefixed.html.d/input.html | 3 ++ .../js-broken-template.d/expected.tags | 1 - main/entry.c | 29 ++++++++++++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 Units/parser-html.r/whitespace-prefixed.html.d/expected.tags create mode 100644 Units/parser-html.r/whitespace-prefixed.html.d/input.html diff --git a/Units/parser-html.r/whitespace-prefixed.html.d/expected.tags b/Units/parser-html.r/whitespace-prefixed.html.d/expected.tags new file mode 100644 index 0000000000..9e54554063 --- /dev/null +++ b/Units/parser-html.r/whitespace-prefixed.html.d/expected.tags @@ -0,0 +1 @@ +heading1 input.html /^<\/h1>$/;" h diff --git a/Units/parser-html.r/whitespace-prefixed.html.d/input.html b/Units/parser-html.r/whitespace-prefixed.html.d/input.html new file mode 100644 index 0000000000..c3727d4d0b --- /dev/null +++ b/Units/parser-html.r/whitespace-prefixed.html.d/input.html @@ -0,0 +1,3 @@ +

+ heading1 +

diff --git a/Units/parser-javascript.r/js-broken-template.d/expected.tags b/Units/parser-javascript.r/js-broken-template.d/expected.tags index 3dec97c22e..e69de29bb2 100644 --- a/Units/parser-javascript.r/js-broken-template.d/expected.tags +++ b/Units/parser-javascript.r/js-broken-template.d/expected.tags @@ -1 +0,0 @@ -\n input.js /^let`$/;" v diff --git a/main/entry.c b/main/entry.c index 04c361b19f..cbbce83711 100644 --- a/main/entry.c +++ b/main/entry.c @@ -1280,8 +1280,25 @@ static void makeTagEntriesForSubwords (tagEntryInfo *const subtag) stringListDelete (list); } -extern int makeTagEntry (const tagEntryInfo *const tag) +static char *trimPrefixedWhitespaces (const char *name) { + const char *start; + + for (start = name; isspace(*start); start++) + ; + + if (start != name) + return eStrdup (start); + + return NULL; +} + +extern int makeTagEntry (const tagEntryInfo *const tag_const) +{ + char *trimmed_name; + const tagEntryInfo *tag = tag_const; + tagEntryInfo tag_backingstore; + int r = CORK_NIL; Assert (tag->name != NULL); @@ -1295,6 +1312,14 @@ extern int makeTagEntry (const tagEntryInfo *const tag) return CORK_NIL; } + trimmed_name = trimPrefixedWhitespaces (tag->name); + if (trimmed_name) + { + tag_backingstore = *tag_const; + tag = &tag_backingstore; + tag_backingstore.name = trimmed_name; + } + if (tag->name [0] == '\0' && (!tag->placeholder)) { if (!doesInputLanguageAllowNullTag()) @@ -1314,6 +1339,8 @@ extern int makeTagEntry (const tagEntryInfo *const tag) makeTagEntriesForSubwords (&subtag); } out: + if (trimmed_name) + eFree (trimmed_name); return r; }