[latexila] Structure: truncate TODOs and FIXMEs if needed
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] Structure: truncate TODOs and FIXMEs if needed
- Date: Tue, 26 Jul 2011 01:20:16 +0000 (UTC)
commit e5172eba424a474174f33e162df4ebd964623f21
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Tue Jul 26 03:19:53 2011 +0200
Structure: truncate TODOs and FIXMEs if needed
The truncation is also done for captions.
And it is now UTF-8 friendly (60 characters max, not bytes).
src/document_structure.vala | 27 +++++++++++++++++++++------
1 files changed, 21 insertions(+), 6 deletions(-)
---
diff --git a/src/document_structure.vala b/src/document_structure.vala
index db4bd58..18e8e37 100644
--- a/src/document_structure.vala
+++ b/src/document_structure.vala
@@ -73,7 +73,9 @@ public class DocumentStructure : GLib.Object
private EnvData? _last_env_data = null;
- private static const int CAPTION_MAX_LENGTH = 60;
+ // Only captions, TODOs and FIXMEs are truncated if needed, because the other
+ // items are normally short enough.
+ private static const int ITEM_MAX_LENGTH = 60;
private static const int MAX_NB_LINES_TO_PARSE = 2000;
private int _start_parsing_line = 0;
@@ -506,8 +508,11 @@ public class DocumentStructure : GLib.Object
return;
}
+ if (type == LowLevelType.TODO || type == LowLevelType.FIXME)
+ add_item ((StructType) type, truncate (contents) ?? contents, iter);
+
// the low-level type is common with the high-level type
- if (type < LowLevelType.NB_COMMON_TYPES)
+ else if (type < LowLevelType.NB_COMMON_TYPES)
add_item ((StructType) type, contents, iter);
// begin of a verbatim env
@@ -522,10 +527,7 @@ public class DocumentStructure : GLib.Object
else if (type == LowLevelType.CAPTION && _last_env_data != null
&& _last_env_data.first_caption == null)
{
- if (contents.length > CAPTION_MAX_LENGTH)
- _last_env_data.first_caption = contents.substring (0, CAPTION_MAX_LENGTH);
- else
- _last_env_data.first_caption = contents;
+ _last_env_data.first_caption = truncate (contents) ?? contents;
}
// end of a figure or table env
@@ -615,6 +617,19 @@ public class DocumentStructure : GLib.Object
_nb_marks = 0;
}
+ // return null if the truncation is not needed
+ private string? truncate (string? text)
+ {
+ if (text == null)
+ return null;
+
+ if (text.char_count () <= ITEM_MAX_LENGTH)
+ return null;
+
+ int index = text.index_of_nth_char (ITEM_MAX_LENGTH);
+ return text.substring (0, index);
+ }
+
private LowLevelType? get_markup_low_level_type (string markup_name)
{
switch (markup_name)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]