summaryrefslogtreecommitdiff
path: root/src/lib/elementary/elm_code_text.c
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2016-11-27 23:13:42 +0000
committerAndy Williams <andy@andywilliams.me>2016-11-27 23:15:46 +0000
commitf6486473ed6a106216655f34042d0ae2218fe046 (patch)
tree5799f52b726b69f4758ccd5f6efd908a7d2d7115 /src/lib/elementary/elm_code_text.c
parent892f4abe3742736dbb02817449da1dd52056ac7f (diff)
elm_code: Slightly smarter indent logic
Continue comment blocks where appropriate... A bunch of refactoring of text/indent code to expand further
Diffstat (limited to 'src/lib/elementary/elm_code_text.c')
-rw-r--r--src/lib/elementary/elm_code_text.c97
1 files changed, 44 insertions, 53 deletions
diff --git a/src/lib/elementary/elm_code_text.c b/src/lib/elementary/elm_code_text.c
index f1503e7..d472894 100644
--- a/src/lib/elementary/elm_code_text.c
+++ b/src/lib/elementary/elm_code_text.c
@@ -210,18 +210,55 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length
210 elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); 210 elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line);
211} 211}
212 212
213Eina_Bool
214_elm_code_text_char_is_whitespace(char c)
215{
216 return c == ' ' || c == '\t';
217}
218
219static unsigned int
220_elm_code_text_trailing_whitespace_length(const char *text, unsigned int length)
221{
222 unsigned int count = 0;
223 char *ptr;
224
225 if (length == 0)
226 return 0;
227
228 ptr = (char *)text + length - 1;
229 while (count < length)
230 {
231 if (!_elm_code_text_char_is_whitespace(*ptr))
232 break;
233
234 count++;
235 ptr--;
236 }
237
238 return count;
239}
240
213EAPI void elm_code_line_text_leading_whitespace_strip(Elm_Code_Line *line) 241EAPI void elm_code_line_text_leading_whitespace_strip(Elm_Code_Line *line)
214{ 242{
215 unsigned int length = 0; 243 unsigned int length, count = 0;
216 unsigned int leading;
217 const char *content; 244 const char *content;
245 char *ptr;
218 246
219 content = elm_code_line_text_get(line, &length); 247 content = elm_code_line_text_get(line, &length);
220 leading = elm_code_text_leading_whitespace_length(content, length); 248 if (length == 0)
221 if (leading == 0)
222 return; 249 return;
223 250
224 elm_code_line_text_remove(line, 0, leading); 251 ptr = (char *)content;
252 while (count < length)
253 {
254 if (!_elm_code_text_char_is_whitespace(*ptr))
255 break;
256
257 count++;
258 ptr++;
259 }
260
261 elm_code_line_text_remove(line, 0, count);
225} 262}
226 263
227EAPI void elm_code_line_text_trailing_whitespace_strip(Elm_Code_Line *line) 264EAPI void elm_code_line_text_trailing_whitespace_strip(Elm_Code_Line *line)
@@ -231,7 +268,7 @@ EAPI void elm_code_line_text_trailing_whitespace_strip(Elm_Code_Line *line)
231 const char *content; 268 const char *content;
232 269
233 content = elm_code_line_text_get(line, &length); 270 content = elm_code_line_text_get(line, &length);
234 trailing = elm_code_text_trailing_whitespace_length(content, length); 271 trailing = _elm_code_text_trailing_whitespace_length(content, length);
235 if (trailing == 0) 272 if (trailing == 0)
236 return; 273 return;
237 274
@@ -269,58 +306,12 @@ elm_code_text_newlinenpos(const char *text, unsigned int length, short *nllen)
269 return crpos; 306 return crpos;
270} 307}
271 308
272static Eina_Bool
273_elm_code_text_char_is_whitespace(char c)
274{
275 return c == ' ' || c == '\t';
276}
277
278EAPI unsigned int
279elm_code_text_leading_whitespace_length(const char *text, unsigned int length)
280{
281 unsigned int count = 0;
282 char *ptr = (char *)text;
283
284 while (count < length)
285 {
286 if (!_elm_code_text_char_is_whitespace(*ptr))
287 break;
288
289 count++;
290 ptr++;
291 }
292
293 return count;
294}
295
296EAPI unsigned int
297elm_code_text_trailing_whitespace_length(const char *text, unsigned int length)
298{
299 unsigned int count = 0;
300 char *ptr;
301
302 if (length == 0)
303 return 0;
304
305 ptr = (char *)text + length - 1;
306 while (count < length)
307 {
308 if (!_elm_code_text_char_is_whitespace(*ptr))
309 break;
310
311 count++;
312 ptr--;
313 }
314
315 return count;
316}
317
318EAPI unsigned int 309EAPI unsigned int
319elm_code_text_is_whitespace(const char *text, unsigned int length) 310elm_code_text_is_whitespace(const char *text, unsigned int length)
320{ 311{
321 unsigned int leading; 312 unsigned int leading;
322 313
323 leading = elm_code_text_trailing_whitespace_length(text, length); 314 leading = _elm_code_text_trailing_whitespace_length(text, length);
324 315
325 return leading == length; 316 return leading == length;
326} 317}