MCPcopy Index your code
hub / github.com/IBM/Project_CodeNet / det_coords_adjust_labels

Function det_coords_adjust_labels

tools/json-graph/src/jsonml2jgf.c:79–129  ·  view source on GitHub ↗

Determine correct coordinates for all tokens (leaf nodes) and adjust all labels by removing leading and trailing white-space. */

Source from the content-addressed store, hash-verified

77 and adjust all labels by removing leading and trailing white-space.
78*/
79static void det_coords_adjust_labels(Graph g)
80{
81 /* Coordinates for some punctuators are (a bit) off. */
82 unsigned line = 1, column = 0;
83 unsigned end_line = 1, end_column = 0;
84 Node n;
85 for (n = g->nodes; n; n = n->next) {
86 /* Strip any white-space at front and back from label.
87 Includes real and escaped TABs and LFs that were put in by
88 the xml-to-jsonml XSLT program.
89 Note: this does not affect any of the token literals.
90 */
91 const char *start = input + n->label->start;
92 const char *end = input + n->label->end;
93 const char *p;
94 for (p = start; p < end; ++p)
95 if (isspace(*p))
96 n->label->start++;
97 else if (*p == '\\' && (*(p+1) == 'n' || *(p+1) == 't')) {
98 n->label->start += 2;
99 ++p;
100 }
101 else
102 break;
103 start = input + n->label->start;
104 for (p = end-1; p >= start; --p)
105 if (isspace(*p))
106 n->label->end--;
107 else if (*(p-1) == '\\' && (*p == 'n' || *p == 't')) {
108 n->label->end -= 2;
109 --p;
110 }
111 else
112 break;
113
114 /* Fish out any pos:start attribute and decode: */
115 coords(attr_find(n->attrs, "pos:start"), &line, &column);
116
117 /* Fish out any pos:end attribute and decode: */
118 coords(attr_find(n->attrs, "pos:end"), &end_line, &end_column);
119
120 /* Only keep coordinates for tokens for now; orig column counts from 1. */
121 if (n->line) { /* this is a token */
122 n->line = line; /* > 0 */
123 n->column = column-1;
124
125 line = end_line;
126 column = end_column+1;
127 }
128 }
129}
130
131static void graph_show_jgf(Graph g, FILE *fp)
132{

Callers 2

graph_show_jgfFunction · 0.85
show_tokensFunction · 0.85

Calls 2

coordsFunction · 0.85
attr_findFunction · 0.85

Tested by

no test coverage detected