summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--unicode/biditest2.C45
-rw-r--r--unicode/book.xml36
-rw-r--r--unicode/courier-unicode.h.in12
-rw-r--r--unicode/unicode_bidi.c22
-rw-r--r--unicode/unicodecpp.C43
5 files changed, 118 insertions, 40 deletions
diff --git a/unicode/biditest2.C b/unicode/biditest2.C
index cbd8c25..0e0472e 100644
--- a/unicode/biditest2.C
+++ b/unicode/biditest2.C
@@ -349,11 +349,46 @@ void character_test()
unicode::bidi_logical_order(logical_string,
logical_levels,
- paragraph);
-
- auto new_string=unicode::bidi_embed(logical_string,
- logical_levels,
- paragraph);
+ paragraph,
+ []
+ (size_t, size_t) {},
+ 0,
+ logical_string.size());
+
+ std::u32string new_string;
+
+ unicode::bidi_embed
+ (logical_string,
+ logical_levels,
+ paragraph,
+ [&]
+ (const char32_t *string,
+ size_t n,
+ bool is_part_of_string)
+ {
+ if ((std::less_equal<const char32_t *>
+ {}(logical_string.c_str(),
+ string) &&
+ std::less<const
+ char32_t *>
+ {}(string,
+ logical_string.c_str()
+ +logical_string.size()))
+ != is_part_of_string)
+ {
+ std::cerr <<
+ "bidi_embed passed in "
+ "wrong value for "
+ "is_part_of_string"
+ << std::endl;
+ exit(1);
+ }
+
+ new_string.insert
+ (new_string.end(),
+ string,
+ string+n);
+ });
auto save_string=new_string;
diff --git a/unicode/book.xml b/unicode/book.xml
index 45686dc..0275058 100644
--- a/unicode/book.xml
+++ b/unicode/book.xml
@@ -381,7 +381,7 @@ See COPYING for distribution information.
<paramdef>const unicode_bidi_level_t *<parameter>levels</parameter></paramdef>
<paramdef>size_t <parameter>n</parameter></paramdef>
<paramdef>unicode_bidi_level_t <parameter>paragraph_embedding</parameter></paramdef>
- <paramdef>void (*<parameter>emit</parameter>)(const char32_t *string, size_t n, void *arg)</paramdef>
+ <paramdef>void (*<parameter>emit</parameter>)(const char32_t *string, size_t n, int is_part_of_string, void *arg)</paramdef>
<paramdef>void *<parameter>arg</parameter></paramdef>
</funcprototype>
@@ -942,6 +942,14 @@ See COPYING for distribution information.
</listitem>
<listitem>
<para>
+ Indication whether the Unicode string pointer is pointing
+ to a part of the original Unicode string that's getting
+ embedded. Otherwise this must be some marker character that's
+ not present in the original Unicode string.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
Forwarded <parameter>arg</parameter> pointer value.
</para>
</listitem>
@@ -2835,7 +2843,7 @@ See COPYING for distribution information.
<funcdef>int <function>unicode::bidi_reorder</function></funcdef>
<paramdef>std::u32string &amp;<parameter>string</parameter></paramdef>
<paramdef>std::vector&lt;unicode_bidi_level_t&gt; &amp;<parameter>embedding_level</parameter></paramdef>
- <paramdef>const std::function&lt;void (size_t, size_t) noexcept&gt; &amp;<parameter>reorder_callback</parameter>=[](size_t, size_t){}</paramdef>
+ <paramdef>const std::function&lt;void (size_t, size_t)&gt; &amp;<parameter>reorder_callback</parameter>=[](size_t, size_t){}</paramdef>
<paramdef>size_t <parameter>starting_pos</parameter>=0</paramdef>
<paramdef>size_t <parameter>n</parameter>=(size_t)-1</paramdef>
</funcprototype>
@@ -2843,7 +2851,7 @@ See COPYING for distribution information.
<funcprototype>
<funcdef>void <function>unicode::bidi_reorder</function></funcdef>
<paramdef>std::vector&lt;unicode_bidi_level_t&gt; &amp;<parameter>embedding_level</parameter></paramdef>
- <paramdef>const std::function&lt;void (size_t, size_t) noexcept&gt; &amp;<parameter>reorder_callback</parameter>=[](size_t, size_t){}</paramdef>
+ <paramdef>const std::function&lt;void (size_t, size_t)&gt; &amp;<parameter>reorder_callback</parameter>=[](size_t, size_t){}</paramdef>
<paramdef>size_t <parameter>starting_pos</parameter>=0</paramdef>
<paramdef>size_t <parameter>n</parameter>=(size_t)-1</paramdef>
</funcprototype>
@@ -2851,7 +2859,7 @@ See COPYING for distribution information.
<funcprototype>
<funcdef>void <function>unicode::bidi_cleanup</function></funcdef>
<paramdef>std::u32string &amp;<parameter>string</parameter></paramdef>
- <paramdef>const std::function&lt;void (size_t) noexcept&gt; &amp;<parameter>removed_callback</parameter>=[](size_t){}</paramdef>
+ <paramdef>const std::function&lt;void (size_t)&gt; &amp;<parameter>removed_callback</parameter>=[](size_t){}</paramdef>
<paramdef>int <parameter>cleanup_options</parameter></paramdef>
</funcprototype>
@@ -2859,7 +2867,7 @@ See COPYING for distribution information.
<funcdef>int <function>unicode::bidi_cleanup</function></funcdef>
<paramdef>std::u32string &amp;<parameter>string</parameter></paramdef>
<paramdef>std::vector &lt;unicode_bidi_level_t&gt; &amp;<parameter>levels</parameter></paramdef>
- <paramdef>const std::function&lt;void (size_t) noexcept&gt; &amp;<parameter>removed_callback</parameter>=[](size_t){}</paramdef>
+ <paramdef>const std::function&lt;void (size_t)&gt; &amp;<parameter>removed_callback</parameter>=[](size_t){}</paramdef>
<paramdef>int <parameter>cleanup_options</parameter>=0</paramdef>
</funcprototype>
@@ -2867,7 +2875,7 @@ See COPYING for distribution information.
<funcdef>int <function>unicode::bidi_cleanup</function></funcdef>
<paramdef>std::u32string &amp;<parameter>string</parameter></paramdef>
<paramdef>std::vector &lt;unicode_bidi_level_t&gt; &amp;<parameter>levels</parameter></paramdef>
- <paramdef>const std::function&lt;void (size_t) noexcept&gt; &amp;<parameter>removed_callback</parameter></paramdef>
+ <paramdef>const std::function&lt;void (size_t)&gt; &amp;<parameter>removed_callback</parameter></paramdef>
<paramdef>int <parameter>cleanup_options</parameter></paramdef>
<paramdef>size_t <parameter>starting_pos</parameter></paramdef>
<paramdef>size_t <parameter>n</parameter></paramdef>
@@ -2878,14 +2886,18 @@ See COPYING for distribution information.
<paramdef>std::u32string &amp;<parameter>string</parameter></paramdef>
<paramdef>std::vector &lt;unicode_bidi_level_t&gt; &amp;<parameter>levels</parameter></paramdef>
<paramdef>unicode_bidi_level_t <parameter>paragraph_embedding</parameter></paramdef>
- <paramdef>const std::function&lt;void (size_t, size_t) noexcept&gt; &amp;<parameter>removed_callback</parameter></paramdef>
+ <paramdef>const std::function&lt;void (size_t, size_t)&gt; &amp;<parameter>reorder_callback</parameter>=[](size_t, size_t){}</paramdef>
+ <paramdef>size_t <parameter>starting_pos</parameter>=0</paramdef>
+ <paramdef>size_t <parameter>n</parameter>=(size_t)-1</paramdef>
</funcprototype>
<funcprototype>
<funcdef>void <function>unicode::bidi_logical_order</function></funcdef>
<paramdef>std::vector &lt;unicode_bidi_level_t&gt; &amp;<parameter>levels</parameter></paramdef>
<paramdef>unicode_bidi_level_t <parameter>paragraph_embedding</parameter></paramdef>
- <paramdef>const std::function&lt;void (size_t, size_t) noexcept&gt; &amp;<parameter>removed_callback</parameter></paramdef>
+ <paramdef>const std::function&lt;void (size_t, size_t)&gt; &amp;<parameter>reorder_callback</parameter></paramdef>
+ <paramdef>size_t <parameter>starting_pos</parameter>=0</paramdef>
+ <paramdef>size_t <parameter>n</parameter>=(size_t)-1</paramdef>
</funcprototype>
<funcprototype>
@@ -2893,7 +2905,7 @@ See COPYING for distribution information.
<paramdef>const std::u32string &amp;<parameter>string</parameter></paramdef>
<paramdef>const std::vector &lt;unicode_bidi_level_t&gt; &amp;<parameter>levels</parameter></paramdef>
<paramdef>unicode_bidi_level_t <parameter>paragraph_embedding</parameter></paramdef>
- <paramdef>const std::function&lt;void (size_t, const char32_t *, size_t) noexcept&gt; &amp;<parameter>callback</parameter></paramdef>
+ <paramdef>const std::function&lt;void (const char32_t *, size_t, bool)&gt; &amp;<parameter>callback</parameter></paramdef>
</funcprototype>
<funcprototype>
@@ -3043,8 +3055,10 @@ auto [levels, level]=unicode::bidi_calc(types);
<listitem>
<para>
- <function>unicode::bidi_reorder</function> and
- <function>unicode::bidi_cleanup</function> take two optional
+ <function>unicode::bidi_reorder</function>,
+ <function>unicode::bidi_cleanup</function>, and
+ <function>unicode::bidi_logical_order</function>
+ take two optional
parameters (defaulted values or overloaded) specifying
an optional starting position and number of characters that
define a subset of the original string that gets reordered
diff --git a/unicode/courier-unicode.h.in b/unicode/courier-unicode.h.in
index 4bc7b55..1c7245c 100644
--- a/unicode/courier-unicode.h.in
+++ b/unicode/courier-unicode.h.in
@@ -698,6 +698,7 @@ extern void unicode_bidi_embed(const char32_t *string,
unicode_bidi_level_t paragraph_embedding,
void (*emit)(const char32_t *string,
size_t n,
+ int,
void *arg),
void *arg);
@@ -2291,12 +2292,16 @@ int bidi_logical_order(std::u32string &string,
std::vector<unicode_bidi_level_t> &levels,
unicode_bidi_level_t paragraph_embedding,
const std::function<void (size_t, size_t)>
- &lambda=[](size_t,size_t){});
+ &lambda=[](size_t,size_t){},
+ size_t starting_pos=0,
+ size_t n=(size_t)-1);
//! Convert Unicode string from canonical rendering order to logical order.
void bidi_logical_order(std::vector<unicode_bidi_level_t> &levels,
unicode_bidi_level_t paragraph_embedding,
- const std::function<void (size_t, size_t)> &lambda);
+ const std::function<void (size_t, size_t)> &lambda,
+ size_t starting_pos=0,
+ size_t n=(size_t)-1);
//! Embed directional and isolation markers
@@ -2309,7 +2314,8 @@ int bidi_embed(const std::u32string &string,
const std::vector<unicode_bidi_level_t> &levels,
unicode_bidi_level_t paragraph_embedding,
const std::function<void (const char32_t *string,
- size_t n)> &lambda);
+ size_t n,
+ bool is_part_of_string)> &lambda);
//! Embed directional and isolation markers
diff --git a/unicode/unicode_bidi.c b/unicode/unicode_bidi.c
index 92fe8a7..73440ed 100644
--- a/unicode/unicode_bidi.c
+++ b/unicode/unicode_bidi.c
@@ -2215,6 +2215,7 @@ static void emit_bidi_embed_levelrun(const char32_t *string,
struct need_marker_info *need_marker,
void (*emit)(const char32_t *string,
size_t n,
+ int is_part_of_string,
void *arg),
void *arg);
@@ -2250,18 +2251,19 @@ static void emit_marker(struct bidi_embed_levelrun *p,
struct need_marker_info *info,
void (*emit)(const char32_t *string,
size_t n,
+ int is_part_of_string,
void *arg),
void *arg)
{
char32_t marker= (p->level & 1) ? UNICODE_RLM:UNICODE_LRM;
if (info->need_marker)
- (*emit)(&marker, 1, arg);
+ (*emit)(&marker, 1, 0, arg);
if (info->need_pdi)
{
marker=UNICODE_PDI;
- (*emit)(&marker, 1, arg);
+ (*emit)(&marker, 1, 0, arg);
}
}
@@ -2271,6 +2273,7 @@ void unicode_bidi_embed(const char32_t *string,
unicode_bidi_level_t paragraph_level,
void (*emit)(const char32_t *string,
size_t n,
+ int is_part_of_string,
void *arg),
void *arg)
{
@@ -2404,7 +2407,7 @@ void unicode_bidi_embed(const char32_t *string,
previous_level=paragraph_level;
- (*emit)(string+p->end, 1, arg);
+ (*emit)(string+p->end, 1, 1, arg);
continue;
}
@@ -2506,6 +2509,7 @@ static void emit_bidi_embed_levelrun(const char32_t *string,
struct need_marker_info *need_marker,
void (*emit)(const char32_t *string,
size_t n,
+ int is_part_of_string,
void *arg),
void *arg)
{
@@ -2561,7 +2565,7 @@ static void emit_bidi_embed_levelrun(const char32_t *string,
char32_t override_start=run->level ? UNICODE_RLI:UNICODE_LRI;
if (run->level != paragraph_level)
- (*emit)(&override_start, 1, arg);
+ (*emit)(&override_start, 1, 0, arg);
/*
** Make sure the character sequence has strong context.
@@ -2637,9 +2641,9 @@ static void emit_bidi_embed_levelrun(const char32_t *string,
*/
if (word_start > start)
(*emit)(string+start,
- word_start-start, arg);
+ word_start-start, 1, arg);
- (*emit)(&override_start, 1, arg);
+ (*emit)(&override_start, 1, 0, arg);
while (++i < end)
{
enum_bidi_type_t t=types[i];
@@ -2657,12 +2661,12 @@ static void emit_bidi_embed_levelrun(const char32_t *string,
fprintf(DEBUGDUMP, "end of word at %d\n",
(int)i);
#endif
- (*emit)(string+word_start, i-word_start, arg);
- (*emit)(&override_end, 1, arg);
+ (*emit)(string+word_start, i-word_start, 1, arg);
+ (*emit)(&override_end, 1, 0, arg);
start=i;
continue;
}
- (*emit)(string+start, i-start, arg);
+ (*emit)(string+start, i-start, 1, arg);
start=i;
}
diff --git a/unicode/unicodecpp.C b/unicode/unicodecpp.C
index 5677b86..10156a4 100644
--- a/unicode/unicodecpp.C
+++ b/unicode/unicodecpp.C
@@ -806,16 +806,24 @@ int unicode::bidi_logical_order(std::u32string &string,
std::vector<unicode_bidi_level_t> &levels,
unicode_bidi_level_t paragraph_embedding,
const std::function<void (size_t, size_t)>
- &lambda)
+ &lambda,
+ size_t starting_pos,
+ size_t n)
{
- if (string.size() != levels.size())
+ auto s=string.size();
+
+ if (s != levels.size())
return -1;
- if (string.empty())
+ if (starting_pos >= s)
return 0;
+ if (n > s-starting_pos)
+ n=s-starting_pos;
+
cb_wrapper<void (size_t, size_t)> cb{lambda};
- unicode_bidi_logical_order(&string[0], &levels[0], string.size(),
+ unicode_bidi_logical_order(&string[starting_pos],
+ &levels[starting_pos], n,
paragraph_embedding,
&reorder_callback,
reinterpret_cast<void *>(&cb));
@@ -826,13 +834,20 @@ int unicode::bidi_logical_order(std::u32string &string,
void unicode::bidi_logical_order(std::vector<unicode_bidi_level_t> &levels,
unicode_bidi_level_t paragraph_embedding,
const std::function<void (size_t, size_t)>
- &lambda)
+ &lambda,
+ size_t starting_pos,
+ size_t n)
{
- if (levels.size() == 0)
+ auto s=levels.size();
+
+ if (starting_pos >= s)
return;
+ if (n > s-starting_pos)
+ n=s-starting_pos;
+
cb_wrapper<void (size_t, size_t)> cb{lambda};
- unicode_bidi_logical_order(NULL, &levels[0], levels.size(),
+ unicode_bidi_logical_order(NULL, &levels[starting_pos], n,
paragraph_embedding,
&reorder_callback,
reinterpret_cast<void *>(&cb));
@@ -842,12 +857,14 @@ void unicode::bidi_logical_order(std::vector<unicode_bidi_level_t> &levels,
extern "C" {
static void embed_callback(const char32_t *string,
size_t n,
+ int is_part_of_string,
void *arg)
{
auto p=reinterpret_cast<cb_wrapper<void
(const char32_t *,
- size_t n)> *>(arg);
- (*p)(string, n);
+ size_t n,
+ bool)> *>(arg);
+ (*p)(string, n, is_part_of_string != 0);
}
}
@@ -855,7 +872,8 @@ int unicode::bidi_embed(const std::u32string &string,
const std::vector<unicode_bidi_level_t> &levels,
unicode_bidi_level_t paragraph_embedding,
const std::function<void (const char32_t *string,
- size_t n)>
+ size_t n,
+ bool is_part_of_string)>
&lambda)
{
if (string.size() != levels.size())
@@ -864,7 +882,7 @@ int unicode::bidi_embed(const std::u32string &string,
if (string.empty())
return 0;
- cb_wrapper<void (const char32_t *, size_t)> cb{lambda};
+ cb_wrapper<void (const char32_t *, size_t, bool)> cb{lambda};
unicode_bidi_embed(&string[0], &levels[0], string.size(),
paragraph_embedding,
embed_callback,
@@ -884,7 +902,8 @@ std::u32string unicode::bidi_embed(const std::u32string &string,
(void)bidi_embed(string, levels, paragraph_embedding,
[&]
(const char32_t *string,
- size_t n)
+ size_t n,
+ bool ignored)
{
new_string.insert(new_string.end(),
string, string+n);