Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/87b5fd1bccc28132405fe34e129e1eb1e4b63f5b
...commit
http://git.netsurf-browser.org/netsurf.git/commit/87b5fd1bccc28132405fe34e129e1eb1e4b63f5b
...tree
http://git.netsurf-browser.org/netsurf.git/tree/87b5fd1bccc28132405fe34e129e1eb1e4b63f5b
The branch, master has been updated
via 87b5fd1bccc28132405fe34e129e1eb1e4b63f5b (commit)
from 60d9dbe390f95fc85b414005ef4b91a7aec0a2fc (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=87b5fd1bccc28132405fe34e129e1eb1e4b63f5b
commit 87b5fd1bccc28132405fe34e129e1eb1e4b63f5b
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>
html: list counter style: Split out symbol copy.
diff --git a/content/handlers/html/list_counter_style.c
b/content/handlers/html/list_counter_style.c
index ae9fb8c..fc54c6c 100644
--- a/content/handlers/html/list_counter_style.c
+++ b/content/handlers/html/list_counter_style.c
@@ -41,14 +41,39 @@ struct list_counter_style {
const unsigned int length;
const symbol_t value;
} pad;
- const char *prefix;
- const char *postfix;
+ symbol_t prefix;
+ symbol_t postfix;
const symbol_t *symbols; /**< array of symbols which represent this
style */
const int *weights; /**< symbol weights for additive schemes */
const size_t items; /**< items in symbol and weight table */
size_t (*calc)(uint8_t *ares, const size_t alen, int value, const
struct list_counter_style *cstyle); /**< function to calculate the system */
};
+/**
+ * Copy a UTF-8 symbol to buffer at offset, if there is space
+ *
+ * \param[in] buf The output buffer
+ * \param[in] buflen The length of \a buf
+ * \param[in] pos Current position in \a buf
+ * \param[in] symbol The symbol to copy into \a buf
+ * \return The number of bytes needed in the output buffer which may be
+ * larger than \a buflen but the buffer will not be overrun
+ */
+static inline size_t
+copy_symbol(char *buf, const size_t buflen, size_t pos, const symbol_t symbol)
+{
+ size_t sidx = 0; /* current symbol index */
+
+ while ((sidx < sizeof(symbol_t)) && (symbol[sidx] != '\0')) {
+ if (pos < buflen) {
+ buf[pos] = symbol[sidx];
+ }
+ pos++;
+ sidx++;
+ }
+
+ return sidx;
+}
/**
* maps alphabet values to output values with a symbol table
@@ -71,53 +96,28 @@ map_aval_to_symbols(char *buf, const size_t buflen,
const struct list_counter_style *cstyle)
{
size_t oidx = 0;
- size_t pidx; /* padding index */
size_t aidx; /* numeral index */
- size_t sidx; /* current symbol index */
- const char *postfix = "."; /* default postfix string */
+ const symbol_t postfix = "."; /* default postfix string */
/* add padding if required */
if (alen < cstyle->pad.length) {
+ size_t pidx; /* padding index */
for (pidx=cstyle->pad.length - alen; pidx > 0; pidx--) {
- sidx=0;
- while ((sidx < 4) &&
- (cstyle->pad.value[sidx] != 0)) {
- if (oidx < buflen) {
- buf[oidx] = cstyle->pad.value[sidx];
- }
- oidx++;
- sidx++;
- }
+ oidx += copy_symbol(buf, buflen, oidx,
+ cstyle->pad.value);
}
}
/* map symbols */
for (aidx=0; aidx < alen; aidx++) {
- sidx=0;
- while ((sidx < 4) &&
- (cstyle->symbols[aval[aidx]][sidx] != 0)) {
- if (oidx < buflen) {
- buf[oidx] = cstyle->symbols[aval[aidx]][sidx];
- }
- oidx++;
- sidx++;
- }
+ oidx += copy_symbol(buf, buflen, oidx,
+ cstyle->symbols[aval[aidx]]);
}
-
/* postfix */
- if (cstyle->postfix != NULL) {
- postfix = cstyle->postfix;
- }
- sidx=0;
- while ((sidx < 4) &&
- (postfix[sidx] != 0)) {
- if (oidx < buflen) {
- buf[oidx] = postfix[sidx];
- }
- oidx++;
- sidx++;
- }
+ oidx += copy_symbol(buf, buflen, oidx,
+ (cstyle->postfix[0] != '\0') ?
+ cstyle->postfix : postfix);
return oidx;
}
-----------------------------------------------------------------------
Summary of changes:
content/handlers/html/list_counter_style.c | 72 ++++++++++++++--------------
1 file changed, 36 insertions(+), 36 deletions(-)
diff --git a/content/handlers/html/list_counter_style.c
b/content/handlers/html/list_counter_style.c
index ae9fb8c..fc54c6c 100644
--- a/content/handlers/html/list_counter_style.c
+++ b/content/handlers/html/list_counter_style.c
@@ -41,14 +41,39 @@ struct list_counter_style {
const unsigned int length;
const symbol_t value;
} pad;
- const char *prefix;
- const char *postfix;
+ symbol_t prefix;
+ symbol_t postfix;
const symbol_t *symbols; /**< array of symbols which represent this
style */
const int *weights; /**< symbol weights for additive schemes */
const size_t items; /**< items in symbol and weight table */
size_t (*calc)(uint8_t *ares, const size_t alen, int value, const
struct list_counter_style *cstyle); /**< function to calculate the system */
};
+/**
+ * Copy a UTF-8 symbol to buffer at offset, if there is space
+ *
+ * \param[in] buf The output buffer
+ * \param[in] buflen The length of \a buf
+ * \param[in] pos Current position in \a buf
+ * \param[in] symbol The symbol to copy into \a buf
+ * \return The number of bytes needed in the output buffer which may be
+ * larger than \a buflen but the buffer will not be overrun
+ */
+static inline size_t
+copy_symbol(char *buf, const size_t buflen, size_t pos, const symbol_t symbol)
+{
+ size_t sidx = 0; /* current symbol index */
+
+ while ((sidx < sizeof(symbol_t)) && (symbol[sidx] != '\0')) {
+ if (pos < buflen) {
+ buf[pos] = symbol[sidx];
+ }
+ pos++;
+ sidx++;
+ }
+
+ return sidx;
+}
/**
* maps alphabet values to output values with a symbol table
@@ -71,53 +96,28 @@ map_aval_to_symbols(char *buf, const size_t buflen,
const struct list_counter_style *cstyle)
{
size_t oidx = 0;
- size_t pidx; /* padding index */
size_t aidx; /* numeral index */
- size_t sidx; /* current symbol index */
- const char *postfix = "."; /* default postfix string */
+ const symbol_t postfix = "."; /* default postfix string */
/* add padding if required */
if (alen < cstyle->pad.length) {
+ size_t pidx; /* padding index */
for (pidx=cstyle->pad.length - alen; pidx > 0; pidx--) {
- sidx=0;
- while ((sidx < 4) &&
- (cstyle->pad.value[sidx] != 0)) {
- if (oidx < buflen) {
- buf[oidx] = cstyle->pad.value[sidx];
- }
- oidx++;
- sidx++;
- }
+ oidx += copy_symbol(buf, buflen, oidx,
+ cstyle->pad.value);
}
}
/* map symbols */
for (aidx=0; aidx < alen; aidx++) {
- sidx=0;
- while ((sidx < 4) &&
- (cstyle->symbols[aval[aidx]][sidx] != 0)) {
- if (oidx < buflen) {
- buf[oidx] = cstyle->symbols[aval[aidx]][sidx];
- }
- oidx++;
- sidx++;
- }
+ oidx += copy_symbol(buf, buflen, oidx,
+ cstyle->symbols[aval[aidx]]);
}
-
/* postfix */
- if (cstyle->postfix != NULL) {
- postfix = cstyle->postfix;
- }
- sidx=0;
- while ((sidx < 4) &&
- (postfix[sidx] != 0)) {
- if (oidx < buflen) {
- buf[oidx] = postfix[sidx];
- }
- oidx++;
- sidx++;
- }
+ oidx += copy_symbol(buf, buflen, oidx,
+ (cstyle->postfix[0] != '\0') ?
+ cstyle->postfix : postfix);
return oidx;
}
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]