summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-08-20 12:07:53 -0400
committerMatthias Clasen <mclasen@redhat.com>2021-08-20 12:21:18 -0400
commit2b097607b7f2b7ab468dcc47f7b58898a1e03b9f (patch)
tree2afe35be4b50b751313473e2bbb06964931a3c7d
parentba5c0b74ed537e8d11491709373a92d69b0aa1f0 (diff)
downloadpango-2b097607b7f2b7ab468dcc47f7b58898a1e03b9f.tar.gz
Cosmetics: Move a function around
pango_find_paragraph_boundary has nothing to do with breaks, so move it to pango-utils.h
-rw-r--r--pango/break.c105
-rw-r--r--pango/pango-break.h6
-rw-r--r--pango/pango-utils.c102
-rw-r--r--pango/pango-utils.h6
4 files changed, 108 insertions, 111 deletions
diff --git a/pango/break.c b/pango/break.c
index 9690d510..9eb4a291 100644
--- a/pango/break.c
+++ b/pango/break.c
@@ -30,7 +30,6 @@
#include <string.h>
#define PARAGRAPH_SEPARATOR 0x2029
-#define PARAGRAPH_SEPARATOR_STRING "\xE2\x80\xA9"
/* See http://www.unicode.org/unicode/reports/tr14/ if you hope
* to understand the line breaking code.
@@ -1655,110 +1654,6 @@ pango_break (const gchar *text,
}
/**
- * pango_find_paragraph_boundary:
- * @text: UTF-8 text
- * @length: length of @text in bytes, or -1 if nul-terminated
- * @paragraph_delimiter_index: (out): return location for index of
- * delimiter
- * @next_paragraph_start: (out): return location for start of next
- * paragraph
- *
- * Locates a paragraph boundary in @text.
- *
- * A boundary is caused by delimiter characters, such as
- * a newline, carriage return, carriage return-newline pair,
- * or Unicode paragraph separator character.
- *
- * The index of the run of delimiters is returned in
- * @paragraph_delimiter_index. The index of the start
- * of the paragrap (index after all delimiters) is stored
- * in @next_paragraph_start.
- *
- * If no delimiters are found, both @paragraph_delimiter_index
- * and @next_paragraph_start are filled with the length of @text
- * (an index one off the end).
- */
-void
-pango_find_paragraph_boundary (const gchar *text,
- gint length,
- gint *paragraph_delimiter_index,
- gint *next_paragraph_start)
-{
- const gchar *p = text;
- const gchar *end;
- const gchar *start = NULL;
- const gchar *delimiter = NULL;
-
- /* Only one character has type G_UNICODE_PARAGRAPH_SEPARATOR in
- * Unicode 5.0; update the following code if that changes.
- */
-
- /* prev_sep is the first byte of the previous separator. Since
- * the valid separators are \r, \n, and PARAGRAPH_SEPARATOR, the
- * first byte is enough to identify it.
- */
- gchar prev_sep;
-
-
- if (length < 0)
- length = strlen (text);
-
- end = text + length;
-
- if (paragraph_delimiter_index)
- *paragraph_delimiter_index = length;
-
- if (next_paragraph_start)
- *next_paragraph_start = length;
-
- if (length == 0)
- return;
-
- prev_sep = 0;
-
- while (p < end)
- {
- if (prev_sep == '\n' ||
- prev_sep == PARAGRAPH_SEPARATOR_STRING[0])
- {
- g_assert (delimiter);
- start = p;
- break;
- }
- else if (prev_sep == '\r')
- {
- /* don't break between \r and \n */
- if (*p != '\n')
- {
- g_assert (delimiter);
- start = p;
- break;
- }
- }
-
- if (*p == '\n' ||
- *p == '\r' ||
- !strncmp(p, PARAGRAPH_SEPARATOR_STRING,
- strlen(PARAGRAPH_SEPARATOR_STRING)))
- {
- if (delimiter == NULL)
- delimiter = p;
- prev_sep = *p;
- }
- else
- prev_sep = 0;
-
- p = g_utf8_next_char (p);
- }
-
- if (delimiter && paragraph_delimiter_index)
- *paragraph_delimiter_index = delimiter - text;
-
- if (start && next_paragraph_start)
- *next_paragraph_start = start - text;
-}
-
-/**
* pango_tailor_break:
* @text: text to process. Must be valid UTF-8
* @length: length in bytes of @text
diff --git a/pango/pango-break.h b/pango/pango-break.h
index 16f3918c..d6438617 100644
--- a/pango/pango-break.h
+++ b/pango/pango-break.h
@@ -101,12 +101,6 @@ void pango_break (const gchar *text,
int attrs_len);
PANGO_AVAILABLE_IN_ALL
-void pango_find_paragraph_boundary (const gchar *text,
- gint length,
- gint *paragraph_delimiter_index,
- gint *next_paragraph_start);
-
-PANGO_AVAILABLE_IN_ALL
void pango_get_log_attrs (const char *text,
int length,
int level,
diff --git a/pango/pango-utils.c b/pango/pango-utils.c
index 894935e7..412f417a 100644
--- a/pango/pango-utils.c
+++ b/pango/pango-utils.c
@@ -1154,3 +1154,105 @@ _pango_shape_get_extents (gint n_chars,
}
}
+/**
+ * pango_find_paragraph_boundary:
+ * @text: UTF-8 text
+ * @length: length of @text in bytes, or -1 if nul-terminated
+ * @paragraph_delimiter_index: (out): return location for index of
+ * delimiter
+ * @next_paragraph_start: (out): return location for start of next
+ * paragraph
+ *
+ * Locates a paragraph boundary in @text.
+ *
+ * A boundary is caused by delimiter characters, such as
+ * a newline, carriage return, carriage return-newline pair,
+ * or Unicode paragraph separator character.
+ *
+ * The index of the run of delimiters is returned in
+ * @paragraph_delimiter_index. The index of the start
+ * of the paragrap (index after all delimiters) is stored
+ * in @next_paragraph_start.
+ *
+ * If no delimiters are found, both @paragraph_delimiter_index
+ * and @next_paragraph_start are filled with the length of @text
+ * (an index one off the end).
+ */
+void
+pango_find_paragraph_boundary (const char *text,
+ int length,
+ int *paragraph_delimiter_index,
+ int *next_paragraph_start)
+{
+ const char *p = text;
+ const char *end;
+ const char *start = NULL;
+ const char *delimiter = NULL;
+
+ /* Only one character has type G_UNICODE_PARAGRAPH_SEPARATOR in
+ * Unicode 5.0; update the following code if that changes.
+ */
+
+ /* prev_sep is the first byte of the previous separator. Since
+ * the valid separators are \r, \n, and PARAGRAPH_SEPARATOR, the
+ * first byte is enough to identify it.
+ */
+ char prev_sep;
+
+#define PARAGRAPH_SEPARATOR_STRING "\xE2\x80\xA9"
+
+ if (length < 0)
+ length = strlen (text);
+
+ end = text + length;
+
+ if (paragraph_delimiter_index)
+ *paragraph_delimiter_index = length;
+
+ if (next_paragraph_start)
+ *next_paragraph_start = length;
+
+ if (length == 0)
+ return;
+
+ prev_sep = 0;
+ while (p < end)
+ {
+ if (prev_sep == '\n' ||
+ prev_sep == PARAGRAPH_SEPARATOR_STRING[0])
+ {
+ g_assert (delimiter);
+ start = p;
+ break;
+ }
+ else if (prev_sep == '\r')
+ {
+ /* don't break between \r and \n */
+ if (*p != '\n')
+ {
+ g_assert (delimiter);
+ start = p;
+ break;
+ }
+ }
+
+ if (*p == '\n' ||
+ *p == '\r' ||
+ !strncmp(p, PARAGRAPH_SEPARATOR_STRING, strlen (PARAGRAPH_SEPARATOR_STRING)))
+ {
+ if (delimiter == NULL)
+ delimiter = p;
+ prev_sep = *p;
+ }
+ else
+ prev_sep = 0;
+
+ p = g_utf8_next_char (p);
+ }
+
+ if (delimiter && paragraph_delimiter_index)
+ *paragraph_delimiter_index = delimiter - text;
+
+ if (start && next_paragraph_start)
+ *next_paragraph_start = start - text;
+}
diff --git a/pango/pango-utils.h b/pango/pango-utils.h
index 04452eb4..49566cf8 100644
--- a/pango/pango-utils.h
+++ b/pango/pango-utils.h
@@ -99,6 +99,12 @@ guint8 * pango_log2vis_get_embedding_levels (const gchar *text,
PANGO_AVAILABLE_IN_1_10
gboolean pango_is_zero_width (gunichar ch) G_GNUC_CONST;
+PANGO_AVAILABLE_IN_ALL
+void pango_find_paragraph_boundary (const char *text,
+ int length,
+ int *paragraph_delimiter_index,
+ int *next_paragraph_start);
+
/* Pango version checking */
/* Encode a Pango version as an integer */