[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[6473] add add_end_sentence method
From: |
Gavin D. Smith |
Subject: |
[6473] add add_end_sentence method |
Date: |
Mon, 27 Jul 2015 12:33:02 +0000 |
Revision: 6473
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6473
Author: gavin
Date: 2015-07-27 12:33:00 +0000 (Mon, 27 Jul 2015)
Log Message:
-----------
add add_end_sentence method
Modified Paths:
--------------
trunk/ChangeLog
trunk/tp/Texinfo/Convert/Line.pm
trunk/tp/Texinfo/Convert/Paragraph.pm
trunk/tp/Texinfo/Convert/Plaintext.pm
trunk/tp/Texinfo/Convert/UnFilled.pm
trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.xs
trunk/tp/Texinfo/Convert/XSParagraph/xspara.c
trunk/tp/Texinfo/Convert/XSParagraph/xspara.h
trunk/tp/t/paragraph.t
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2015-07-27 11:30:58 UTC (rev 6472)
+++ trunk/ChangeLog 2015-07-27 12:33:00 UTC (rev 6473)
@@ -3,6 +3,10 @@
* tp/Texinfo/Convert/XSParagraph/xspara.c: Remove all comments
with out-of-date line numbers for Paragraph.pm.
+ * tp/Texinfo/Convert/Paragraph.pm
+ (inhibit_end_sentence, remove_end_sentence): Rename.
+ (add_end_sentence): New function, split from _add_next.
+
2015-07-27 Gavin Smith <address@hidden>
* tp/Texinfo/Convert/Paragraph.pm,
Modified: trunk/tp/Texinfo/Convert/Line.pm
===================================================================
--- trunk/tp/Texinfo/Convert/Line.pm 2015-07-27 11:30:58 UTC (rev 6472)
+++ trunk/tp/Texinfo/Convert/Line.pm 2015-07-27 12:33:00 UTC (rev 6473)
@@ -151,25 +151,23 @@
return $result;
}
-sub add_next($;$$$)
+sub add_next($;$$)
{
my $line = shift;
my $word = shift;
- my $end_sentence = shift;
my $transparent = shift;
$line->{'end_line_count'} = 0;
- return $line->_add_next($word, $end_sentence, $transparent);
+ return $line->_add_next($word, $transparent);
}
my $end_sentence_character = quotemeta('.?!');
my $after_punctuation_characters = quotemeta('"\')]');
-# add a word and/or end of sentence.
-sub _add_next($;$$$)
+# add a word
+sub _add_next($;$$)
{
my $line = shift;
my $word = shift;
- my $end_sentence = shift;
my $transparent = shift;
my $result = '';
@@ -209,18 +207,22 @@
}
}
- if (defined($end_sentence)) {
- $line->{'end_sentence'} = $end_sentence;
- }
return $result;
}
-sub inhibit_end_sentence($)
+sub remove_end_sentence($)
{
my $line = shift;
$line->{'end_sentence'} = 0;
}
+sub add_end_sentence($;$)
+{
+ my $line = shift;
+ my $value = shift;
+ $line->{'end_sentence'} = $value;
+}
+
sub allow_end_sentence($)
{
my $line = shift;
Modified: trunk/tp/Texinfo/Convert/Paragraph.pm
===================================================================
--- trunk/tp/Texinfo/Convert/Paragraph.pm 2015-07-27 11:30:58 UTC (rev
6472)
+++ trunk/tp/Texinfo/Convert/Paragraph.pm 2015-07-27 12:33:00 UTC (rev
6473)
@@ -19,7 +19,7 @@
# this module has nothing Texinfo specific. In contrast with existing
# modules Text::Wrap, Text::Format, it keeps a state of the paragraph
-# and wait for text to be feed.
+# and waits for text to be fed into it.
package Texinfo::Convert::Paragraph;
@@ -171,22 +171,20 @@
# Any end of sentence punctuation in $WORD that should be allowed to end a
# sentence but which would otherwise be preceded by an upper-case letter
should
# instead by preceded by a backspace character.
-sub add_next($;$$$)
+sub add_next($;$$)
{
my $paragraph = shift;
my $word = shift;
- my $end_sentence = shift;
my $transparent = shift;
$paragraph->{'end_line_count'} = 0;
- return _add_next($paragraph, $word, $end_sentence, $transparent);
+ return _add_next($paragraph, $word, $transparent);
}
# add a word and/or end of sentence.
-sub _add_next($;$$$$)
+sub _add_next($;$$$)
{
my $paragraph = shift;
my $word = shift;
- my $end_sentence = shift;
my $transparent = shift;
my $newlines_impossible = shift;
my $result = '';
@@ -252,18 +250,21 @@
$result .= _cut_line($paragraph);
}
}
- if (defined($end_sentence)) {
- $paragraph->{'end_sentence'} = $end_sentence;
- }
return $result;
}
-sub inhibit_end_sentence($)
+sub remove_end_sentence($)
{
my $paragraph = shift;
$paragraph->{'end_sentence'} = 0;
}
+sub add_end_sentence($;$) {
+ my $paragraph = shift;
+ my $value = shift;
+ $paragraph->{'end_sentence'} = $value;
+}
+
sub allow_end_sentence($)
{
my $paragraph = shift;
@@ -402,7 +403,7 @@
$disinhibit = 1;
}
- $result .= _add_next($paragraph, $added_word, undef, undef,
+ $result .= _add_next($paragraph, $added_word, undef,
!$newline_possible_flag);
# Check if it is considered as an end of sentence. There are two things
Modified: trunk/tp/Texinfo/Convert/Plaintext.pm
===================================================================
--- trunk/tp/Texinfo/Convert/Plaintext.pm 2015-07-27 11:30:58 UTC (rev
6472)
+++ trunk/tp/Texinfo/Convert/Plaintext.pm 2015-07-27 12:33:00 UTC (rev
6473)
@@ -1751,7 +1751,7 @@
my $command = $root->{'cmdname'};
if (defined($no_brace_commands{$command})) {
if ($command eq ':') {
- $formatter->{'container'}->inhibit_end_sentence();
+ $formatter->{'container'}->remove_end_sentence();
return '';
} elsif ($command eq '*') {
$result = _count_added($self, $formatter->{'container'},
@@ -1760,7 +1760,8 @@
$formatter->{'container'}->end_line());
} elsif ($command eq '.' or $command eq '?' or $command eq '!') {
$result .= _count_added($self, $formatter->{'container'},
- $formatter->{'container'}->add_next($command, 1));
+ $formatter->{'container'}->add_next($command));
+ $formatter->{'container'}->add_end_sentence(1);
} elsif ($command eq ' ' or $command eq "\n" or $command eq "\t") {
$result .= _count_added($self, $formatter->{'container'},
$formatter->{'container'}->add_next($no_brace_commands{$command}));
@@ -1799,7 +1800,8 @@
if ($punctuation_no_arg_commands{$command}) {
$result .= _count_added($self, $formatter->{'container'},
- $formatter->{'container'}->add_next($text, 1));
+ $formatter->{'container'}->add_next($text));
+ $formatter->{'container'}->add_end_sentence(1);
} elsif ($command eq 'tie') {
$formatter->{'w'}++;
$result .= _count_added($self, $formatter->{'container'},
@@ -1821,7 +1823,7 @@
}
if ($command eq 'dots') {
- $formatter->{'container'}->inhibit_end_sentence();
+ $formatter->{'container'}->remove_end_sentence();
}
}
if ($formatter->{'var'}
@@ -1860,7 +1862,7 @@
# in case the text added ends with punctuation.
# If the text is empty (likely because of an error) previous
# punctuation will be cancelled, we don't want that.
- $formatter->{'container'}->inhibit_end_sentence()
+ $formatter->{'container'}->remove_end_sentence()
if ($accented_text ne '');
return $result;
} elsif ($self->{'style_map'}->{$command}
@@ -1917,8 +1919,7 @@
$formatter->{'font_type_stack'}->[-1]->{'code_command'}++;
}
$result .= _count_added($self, $formatter->{'container'},
- $formatter->{'container'}->add_next($text_before,
- undef, 1))
+ $formatter->{'container'}->add_next($text_before, 1))
if ($text_before ne '');
if ($root->{'args'}) {
$result .= $self->_convert($root->{'args'}->[0]);
@@ -1934,8 +1935,7 @@
}
}
$result .= _count_added($self, $formatter->{'container'},
- $formatter->{'container'}->add_next($text_after,
- undef, 1))
+ $formatter->{'container'}->add_next($text_after, 1))
if ($text_after ne '');
if ($command eq 'w') {
$formatter->{'w'}--;
@@ -2058,8 +2058,8 @@
$self->_error_outside_of_any_node($root);
}
$result .= _count_added($self, $formatter->{'container'},
- $formatter->{'container'}->add_next("($formatted_footnote_number)",
- undef, 1));
+ $formatter->{'container'}->add_next
+ ("($formatted_footnote_number)", 1));
if ($self->get_conf('footnotestyle') eq 'separate' and $self->{'node'}) {
$result .= $self->_convert({'contents' =>
[{'text' => ' ('},
Modified: trunk/tp/Texinfo/Convert/UnFilled.pm
===================================================================
--- trunk/tp/Texinfo/Convert/UnFilled.pm 2015-07-27 11:30:58 UTC (rev
6472)
+++ trunk/tp/Texinfo/Convert/UnFilled.pm 2015-07-27 12:33:00 UTC (rev
6473)
@@ -147,11 +147,10 @@
}
# add a word and/or end of sentence.
-sub add_next($;$$$)
+sub add_next($;$$)
{
my $line = shift;
my $word = shift;
- my $end_sentence = shift;
my $transparent = shift;
$line->{'end_line_count'} = 0;
my $result = '';
@@ -162,11 +161,16 @@
return $result;
}
-sub inhibit_end_sentence($)
+sub remove_end_sentence($)
{
my $line = shift;
}
+sub add_end_sentence($;$)
+{
+ my $line = shift;
+}
+
sub allow_end_sentence($)
{
my $line = shift;
Modified: trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.xs
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.xs 2015-07-27 11:30:58 UTC
(rev 6472)
+++ trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.xs 2015-07-27 12:33:00 UTC
(rev 6473)
@@ -190,30 +190,17 @@
STRLEN text_len;
//int utf8;
char *retval;
- int end_sentence = -2;
CODE:
- items -= 2;
+ /* TODO: Propagate 'transparent' argument. */
- if (items > 0)
- {
- if (SvOK(ST(2)))
- {
- end_sentence = (int)SvIV(ST(2));
- }
- items--;
- }
-
/* Always convert the input to UTF8 with sv_utf8_upgrade, so we can
process it properly in xspara_add_next. */
if (!SvUTF8 (text_in))
- {
- sv_utf8_upgrade (text_in);
- }
+ sv_utf8_upgrade (text_in);
text = SvPV (text_in, text_len);
//xspara_set_state (paragraph);
- //fprintf (stderr, "end sentence %d\n", end_sentence);
- retval = xspara_add_next (text, text_len, end_sentence);
+ retval = xspara_add_next (text, text_len);
xspara_get_state (paragraph);
RETVAL = newSVpv (retval, 0);
@@ -224,14 +211,27 @@
void
-xspara_inhibit_end_sentence (paragraph)
+xspara_remove_end_sentence (paragraph)
HV * paragraph
CODE:
//xspara_set_state (paragraph);
- xspara_inhibit_end_sentence ();
+ xspara_remove_end_sentence ();
xspara_get_state (paragraph);
void
+xspara_add_end_sentence (paragraph, value)
+ HV * paragraph
+ SV * value
+ PREINIT:
+ int intvalue = 0;
+ CODE:
+ if (SvOK(value))
+ intvalue = (int)SvIV(value);
+ //xspara_set_state (paragraph);
+ xspara_add_end_sentence (intvalue);
+ xspara_get_state (paragraph);
+
+void
xspara_allow_end_sentence (paragraph)
HV * paragraph
CODE:
Modified: trunk/tp/Texinfo/Convert/XSParagraph/xspara.c
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/xspara.c 2015-07-27 11:30:58 UTC
(rev 6472)
+++ trunk/tp/Texinfo/Convert/XSParagraph/xspara.c 2015-07-27 12:33:00 UTC
(rev 6473)
@@ -524,9 +524,7 @@
of the line start a new one. */
void
xspara__add_next (TEXT *result,
- char *word, int word_len,
- int end_sentence,
- int transparent)
+ char *word, int word_len, int transparent)
{
if (word)
{
@@ -612,24 +610,18 @@
xspara__cut_line (result);
}
}
-
- if (end_sentence != -2)
- {
- //fprintf (stderr, "end sentence %d\n", end_sentence);
- state.end_sentence = end_sentence;
- }
}
/* Like _add_next but zero end_line_count at beginning. */
char *
-xspara_add_next (char *text, int text_len, int end_sentence)
+xspara_add_next (char *text, int text_len)
{
TEXT t;
text_init (&t);
state.end_line_count = 0;
//fprintf (stderr, "PASSED EOS %d\n", end_sentence);
- xspara__add_next (&t, text, text_len, end_sentence, 0);
+ xspara__add_next (&t, text, text_len, 0);
if (t.space > 0)
return t.text;
@@ -638,12 +630,18 @@
}
void
-xspara_inhibit_end_sentence (void)
+xspara_remove_end_sentence (void)
{
state.end_sentence = 0;
}
void
+xspara_add_end_sentence (int value)
+{
+ state.end_sentence = value;
+}
+
+void
xspara_allow_end_sentence (void)
{
state.last_letter = L'a'; /* A lower-case letter. */
@@ -957,7 +955,7 @@
memcpy (added_word, p, char_len);
added_word[char_len] = '\0';
- xspara__add_next (&result, added_word, char_len, -2, 0);
+ xspara__add_next (&result, added_word, char_len, 0);
free (added_word);
/* Now check if it is considered as an end of sentence, and
Modified: trunk/tp/Texinfo/Convert/XSParagraph/xspara.h
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/xspara.h 2015-07-27 11:30:58 UTC
(rev 6472)
+++ trunk/tp/Texinfo/Convert/XSParagraph/xspara.h 2015-07-27 12:33:00 UTC
(rev 6473)
@@ -2,7 +2,7 @@
void xspara_set_state (HV *state);
void xspara_get_state (HV *state);
int xspara_init (void);
-char *xspara_add_next (char *, int, int end_sentence);
+char *xspara_add_next (char *, int);
char *xspara_add_text (char *);
char *xspara_set_space_protection (int space_protection, int ignore_columns,
int keep_end_lines, int french_spacing);
@@ -12,5 +12,6 @@
char *xspara_end (void);
char *xspara_add_pending_word (int add_spaces);
void xspara_allow_end_sentence (void);
-void xspara_inhibit_end_sentence (void);
+void xspara_remove_end_sentence (void);
+void xspara_add_end_sentence (int value);
int xspara_end_line_count (void);
Modified: trunk/tp/t/paragraph.t
===================================================================
--- trunk/tp/t/paragraph.t 2015-07-27 11:30:58 UTC (rev 6472)
+++ trunk/tp/t/paragraph.t 2015-07-27 12:33:00 UTC (rev 6473)
@@ -282,7 +282,8 @@
$para = Texinfo::Convert::Paragraph->new();
$result = '';
$result .= $para->add_text('aA');
-$result .= $para->add_next('.', 1);
+$result .= $para->add_next('.');
+$para->add_end_of_sentence(1);
$result .= $para->add_text(' after');
$result .= $para->end();
is ($result, "aA. after\n", 'force end sentence after upper case');
@@ -290,7 +291,8 @@
$para = Texinfo::Convert::Paragraph->new();
$result = '';
$result .= $para->add_text('aa');
-$result .= $para->add_next('.', 1);
+$result .= $para->add_next('.');
+$para->add_end_of_sentence(1);
$result .= $para->add_text('b c');
$result .= $para->end();
is ($result, "aa.b c\n", 'force end sentence followed by text');
@@ -314,7 +316,7 @@
$para = Texinfo::Convert::Paragraph->new();
$result = '';
$result .= $para->add_text('aa.)');
-$para->inhibit_end_sentence();
+$para->remove_end_sentence();
$result .= $para->add_text(' after');
$result .= $para->end();
is ($result, "aa.) after\n", 'inhibit end sentence');
@@ -322,7 +324,7 @@
$para = Texinfo::Convert::Paragraph->new();
$result = '';
$result .= $para->add_text('aa.)');
-$para->inhibit_end_sentence();
+$para->remove_end_sentence();
$result .= $para->add_next('_');
$result .= $para->add_text(' after');
$result .= $para->end();
@@ -331,7 +333,7 @@
$para = Texinfo::Convert::Paragraph->new();
$result = '';
$result .= $para->add_text('aa.)');
-$para->inhibit_end_sentence();
+$para->remove_end_sentence();
$result .= $para->add_text('aa.)');
$result .= $para->add_text(' after');
$result .= $para->end();
@@ -340,7 +342,7 @@
$para = Texinfo::Convert::Paragraph->new();
$result = '';
$result .= $para->add_text('aa.)');
-$para->inhibit_end_sentence();
+$para->remove_end_sentence();
$result .= $para->add_text('))');
$result .= $para->add_text(' after');
$result .= $para->end();
@@ -544,7 +546,7 @@
$line = Texinfo::Convert::Line->new();
$result = '';
$result .= $line->add_text("A");
-$result .= $line->add_next('_', undef, 1);
+$result .= $line->add_next('_', 1);
$result .= $line->add_text(".)");
$result .= $line->add_text(" Next");
$result .= $line->end();
@@ -571,7 +573,8 @@
$para = Texinfo::Convert::Line->new();
$result = '';
$result .= $line->add_text('aA');
-$result .= $line->add_next('.', 1);
+$result .= $line->add_next('.');
+$line->add_end_of_sentence(1);
$result .= $line->add_text(' after');
$result .= $line->end();
is ($result, "aA. after", 'line force end sentence after upper case');
@@ -595,7 +598,7 @@
$line = Texinfo::Convert::Line->new();
$result = '';
$result .= $line->add_text('aa.)');
-$line->inhibit_end_sentence();
+$line->remove_end_sentence();
$result .= $line->add_text(' after');
$result .= $line->end();
is ($result, "aa.) after", 'line inhibit end sentence');
@@ -603,7 +606,7 @@
$line = Texinfo::Convert::Line->new();
$result = '';
$result .= $line->add_text('aa.)');
-$line->inhibit_end_sentence();
+$line->remove_end_sentence();
$result .= $line->add_next('_');
$result .= $line->add_text(' after');
$result .= $line->end();
@@ -612,7 +615,7 @@
$line = Texinfo::Convert::Line->new();
$result = '';
$result .= $line->add_text('aa.)');
-$line->inhibit_end_sentence();
+$line->remove_end_sentence();
$result .= $line->add_text('aa.)');
$result .= $line->add_text(' after');
$result .= $line->end();
@@ -621,7 +624,7 @@
$line = Texinfo::Convert::Line->new();
$result = '';
$result .= $line->add_text('aa.)');
-$line->inhibit_end_sentence();
+$line->remove_end_sentence();
$result .= $line->add_text('))');
$result .= $line->add_text(' after');
$result .= $line->end();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [6473] add add_end_sentence method,
Gavin D. Smith <=