[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Thu, 1 Feb 2024 17:51:30 -0500 (EST) |
branch: master
commit 39ccd09203551b89526ffef2e9ba1fab74676768
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Feb 1 23:51:15 2024 +0100
* tp/Texinfo/XS/main/get_perl_info.c
(copy_sv_options_for_convert_text): fetch ASCII_GLYPH, NUMBER_SECTIONS
and set_case.
* tp/t/convert_to_text.t: test 'set_case' value set as a
Texinfo::Convert::Text::convert_to_text call option.
---
ChangeLog | 9 +++++++++
tp/Texinfo/Convert/Text.pm | 2 +-
tp/Texinfo/XS/main/get_perl_info.c | 27 ++++++++++++++++---------
tp/t/convert_to_text.t | 40 +++++++++++++++++++++++++++++++++++++-
4 files changed, 67 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 3237517fd7..ebf52e05c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-02-01 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/main/get_perl_info.c
+ (copy_sv_options_for_convert_text): fetch ASCII_GLYPH, NUMBER_SECTIONS
+ and set_case.
+
+ * tp/t/convert_to_text.t: test 'set_case' value set as a
+ Texinfo::Convert::Text::convert_to_text call option.
+
2024-02-01 Patrice Dumas <pertusus@free.fr>
* tp/Makefile.am (test_files),
diff --git a/tp/Texinfo/Convert/Text.pm b/tp/Texinfo/Convert/Text.pm
index 1650e6a635..e10b62242a 100644
--- a/tp/Texinfo/Convert/Text.pm
+++ b/tp/Texinfo/Convert/Text.pm
@@ -209,7 +209,7 @@ foreach my $type ('ignorable_spaces_after_command',
my @text_indicator_converter_options
- = ('NUMBER_SECTIONS', 'ASCII_GLYPH', 'TEST');
+ = ('ASCII_GLYPH', 'NUMBER_SECTIONS', 'TEST');
sub _initialize_options_encoding($$)
{
diff --git a/tp/Texinfo/XS/main/get_perl_info.c
b/tp/Texinfo/XS/main/get_perl_info.c
index 1f4cb6ae8c..9152dc5a4c 100644
--- a/tp/Texinfo/XS/main/get_perl_info.c
+++ b/tp/Texinfo/XS/main/get_perl_info.c
@@ -30,14 +30,6 @@
#undef context
-/*
-FIXME add an initialization of translations?
-
-#ifdef ENABLE_NLS
-#include <libintl.h>
-#endif
-*/
-
#include "options_types.h"
#include "document_types.h"
#include "converter_types.h"
@@ -915,24 +907,37 @@ force_conf (CONVERTER *converter, const char *conf, SV
*value)
/* output format specific */
/* map hash reference of Convert::Text options to TEXT_OPTIONS */
-/* TODO more to do? set_case? */
+/* _raw_state is not fetched, as it is not documented as an option,
+ and there is no way to set it through text options either, it can only
+ be set as a state during conversion */
#define FETCH(key) key##_sv = hv_fetch (hv_in, #key, strlen(#key), 0);
TEXT_OPTIONS *
copy_sv_options_for_convert_text (SV *sv_in)
{
HV *hv_in;
SV **_code_state_sv;
+ SV **ASCII_GLYPH_sv;
+ SV **NUMBER_SECTIONS_sv;
SV **TEST_sv;
SV **INCLUDE_DIRECTORIES_sv;
SV **converter_sv;
SV **enabled_encoding_sv;
SV **sort_string_sv;
+ SV **set_case_sv;
TEXT_OPTIONS *text_options = new_text_options ();
dTHX;
hv_in = (HV *)SvRV (sv_in);
+ FETCH(ASCII_GLYPH)
+ if (ASCII_GLYPH_sv)
+ text_options->ASCII_GLYPH = SvIV (*ASCII_GLYPH_sv);
+
+ FETCH(NUMBER_SECTIONS)
+ if (NUMBER_SECTIONS_sv)
+ text_options->NUMBER_SECTIONS = SvIV (*NUMBER_SECTIONS_sv);
+
FETCH(TEST)
if (TEST_sv)
text_options->TEST = SvIV (*TEST_sv);
@@ -945,6 +950,10 @@ copy_sv_options_for_convert_text (SV *sv_in)
if (enabled_encoding_sv)
text_options->encoding = strdup (SvPVutf8_nolen (*enabled_encoding_sv));
+ FETCH(set_case)
+ if (set_case_sv)
+ text_options->set_case = SvIV (*set_case_sv);
+
FETCH(_code_state)
if (_code_state_sv)
text_options->code_state = SvIV (*_code_state_sv);
diff --git a/tp/t/convert_to_text.t b/tp/t/convert_to_text.t
index 2e01ec5c6e..61b59b3063 100644
--- a/tp/t/convert_to_text.t
+++ b/tp/t/convert_to_text.t
@@ -1,11 +1,12 @@
use strict;
+use utf8;
use lib '.';
use Texinfo::ModulePath (undef, undef, undef, 'updirs' => 2);
use Test::More;
-BEGIN { plan tests => 2; }
+BEGIN { plan tests => 5; }
use Texinfo::Parser;
use Texinfo::Document;
@@ -112,3 +113,40 @@ Annexe A Conclusion
', 'test add_heading_number translations with a converter');
#print STDERR "RRR '$result_text'\n";
+
+
+
+# Text setting the set_case options for Text conversion. It is documented
+# that it may be used as an option to convert_to_text in the POD, but there
+# is no way to test it except when called from code.
+
+$document = $parser->parse_texi_piece ('
+Some text. @^o. @aa{}. @AA{}. @copyright{}.
+');
+
+$result_text
+ = Texinfo::Convert::Text::convert_to_text($document->tree(),
+ {'set_case' => 1});
+is ($result_text, '
+SOME TEXT. O^. AA. AA. (C).
+', 'set_case > 0, no encoding');
+
+
+$result_text
+ = Texinfo::Convert::Text::convert_to_text($document->tree(),
+ {'set_case' => -1});
+is ($result_text, '
+some text. o^. aa. aa. (C).
+', 'set_case < 0, no encoding');
+
+$result_text
+ = Texinfo::Convert::Text::convert_to_text($document->tree(),
+ {'set_case' => -1, 'enabled_encoding' => 'utf-8'});
+# since all the characters can be encoded in latin1, perl internal encoding
+# of those characters may be latin1, and a simple print may show result
+# encoded in latin1.
+is ($result_text, '
+some text. ô. å. å. ©.
+', 'set_case < 0, utf-8 encoding');
+
+#print STDERR "RRR '$result_text'\n";