mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-10 18:58:10 +00:00
texstream: implement way to terminate a command depending on the context
i.e., * space if non terminating char follows * {} if space follows * nothing if \, { or } follow
This commit is contained in:
parent
e8b1ec66fc
commit
66f7c2930a
@ -59,11 +59,23 @@ void otexrowstream::put(char_type const & c)
|
|||||||
|
|
||||||
void otexstream::put(char_type const & c)
|
void otexstream::put(char_type const & c)
|
||||||
{
|
{
|
||||||
|
bool isprotected = false;
|
||||||
if (protectspace_) {
|
if (protectspace_) {
|
||||||
if (!canbreakline_ && c == ' ')
|
if (!canbreakline_ && c == ' ') {
|
||||||
os() << "{}";
|
os() << "{}";
|
||||||
|
isprotected = true;
|
||||||
|
}
|
||||||
protectspace_ = false;
|
protectspace_ = false;
|
||||||
}
|
}
|
||||||
|
if (terminate_command_) {
|
||||||
|
if ((c == ' ' || c == '\0') && !isprotected)
|
||||||
|
// A space follows. Terminate with brackets.
|
||||||
|
os() << "{}";
|
||||||
|
else if (c != '\\' && c != '{' && c != '}')
|
||||||
|
// Non-terminating character follows. Terminate with space.
|
||||||
|
os() << " ";
|
||||||
|
terminate_command_ = false;
|
||||||
|
}
|
||||||
otexrowstream::put(c);
|
otexrowstream::put(c);
|
||||||
lastChar(c);
|
lastChar(c);
|
||||||
}
|
}
|
||||||
@ -89,6 +101,7 @@ TexString otexstringstream::release()
|
|||||||
|
|
||||||
BreakLine breakln;
|
BreakLine breakln;
|
||||||
SafeBreakLine safebreakln;
|
SafeBreakLine safebreakln;
|
||||||
|
TerminateCommand termcmd;
|
||||||
|
|
||||||
|
|
||||||
otexstream & operator<<(otexstream & ots, BreakLine)
|
otexstream & operator<<(otexstream & ots, BreakLine)
|
||||||
@ -98,6 +111,7 @@ otexstream & operator<<(otexstream & ots, BreakLine)
|
|||||||
ots.lastChar('\n');
|
ots.lastChar('\n');
|
||||||
}
|
}
|
||||||
ots.protectSpace(false);
|
ots.protectSpace(false);
|
||||||
|
ots.terminateCommand(false);
|
||||||
return ots;
|
return ots;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +124,14 @@ otexstream & operator<<(otexstream & ots, SafeBreakLine)
|
|||||||
ots.lastChar('\n');
|
ots.lastChar('\n');
|
||||||
}
|
}
|
||||||
ots.protectSpace(false);
|
ots.protectSpace(false);
|
||||||
|
ots.terminateCommand(false);
|
||||||
|
return ots;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
otexstream & operator<<(otexstream & ots, TerminateCommand)
|
||||||
|
{
|
||||||
|
ots.terminateCommand(true);
|
||||||
return ots;
|
return ots;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,11 +174,24 @@ otexstream & operator<<(otexstream & ots, TexString ts)
|
|||||||
return ots;
|
return ots;
|
||||||
|
|
||||||
otexrowstream & otrs = ots;
|
otexrowstream & otrs = ots;
|
||||||
|
bool isprotected = false;
|
||||||
|
char const c = ts.str[0];
|
||||||
if (ots.protectSpace()) {
|
if (ots.protectSpace()) {
|
||||||
if (!ots.canBreakLine() && ts.str[0] == ' ')
|
if (!ots.canBreakLine() && c == ' ') {
|
||||||
otrs << "{}";
|
otrs << "{}";
|
||||||
|
isprotected = true;
|
||||||
|
}
|
||||||
ots.protectSpace(false);
|
ots.protectSpace(false);
|
||||||
}
|
}
|
||||||
|
if (ots.terminateCommand()) {
|
||||||
|
if ((c == ' ' || c == '\0') && !isprotected)
|
||||||
|
// A space follows. Terminate with brackets.
|
||||||
|
otrs << "{}";
|
||||||
|
else if (c != '\\' && c != '{' && c != '}')
|
||||||
|
// Non-terminating character follows. Terminate with space.
|
||||||
|
otrs << " ";
|
||||||
|
ots.terminateCommand(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (len > 1)
|
if (len > 1)
|
||||||
ots.canBreakLine(ts.str[len - 2] != '\n');
|
ots.canBreakLine(ts.str[len - 2] != '\n');
|
||||||
@ -183,11 +218,24 @@ otexstream & operator<<(otexstream & ots, docstring const & s)
|
|||||||
if (len == 0)
|
if (len == 0)
|
||||||
return ots;
|
return ots;
|
||||||
otexrowstream & otrs = ots;
|
otexrowstream & otrs = ots;
|
||||||
|
bool isprotected = false;
|
||||||
|
char const c = s[0];
|
||||||
if (ots.protectSpace()) {
|
if (ots.protectSpace()) {
|
||||||
if (!ots.canBreakLine() && s[0] == ' ')
|
if (!ots.canBreakLine() && c == ' ') {
|
||||||
otrs << "{}";
|
otrs << "{}";
|
||||||
|
isprotected = true;
|
||||||
|
}
|
||||||
ots.protectSpace(false);
|
ots.protectSpace(false);
|
||||||
}
|
}
|
||||||
|
if (ots.terminateCommand()) {
|
||||||
|
if ((c == ' ' || c == '\0') && !isprotected)
|
||||||
|
// A space follows. Terminate with brackets.
|
||||||
|
otrs << "{}";
|
||||||
|
else if (c != '\\' && c != '{' && c != '}')
|
||||||
|
// Non-terminating character follows. Terminate with space.
|
||||||
|
otrs << " ";
|
||||||
|
ots.terminateCommand(false);
|
||||||
|
}
|
||||||
|
|
||||||
if (contains(s, 0xF0000)) {
|
if (contains(s, 0xF0000)) {
|
||||||
// Some encoding changes for the underlying stream are embedded
|
// Some encoding changes for the underlying stream are embedded
|
||||||
@ -290,6 +338,7 @@ otexstream & operator<<(otexstream & ots, Type value)
|
|||||||
ots.os() << value;
|
ots.os() << value;
|
||||||
ots.lastChar(0);
|
ots.lastChar(0);
|
||||||
ots.protectSpace(false);
|
ots.protectSpace(false);
|
||||||
|
ots.terminateCommand(false);
|
||||||
return ots;
|
return ots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,8 @@ public:
|
|||||||
///
|
///
|
||||||
explicit otexstream(odocstream & os)
|
explicit otexstream(odocstream & os)
|
||||||
: otexrowstream(os), canbreakline_(false),
|
: otexrowstream(os), canbreakline_(false),
|
||||||
protectspace_(false), parbreak_(true), lastchar_(0) {}
|
protectspace_(false), terminate_command_(false),
|
||||||
|
parbreak_(true), lastchar_(0) {}
|
||||||
///
|
///
|
||||||
void put(char_type const & c);
|
void put(char_type const & c);
|
||||||
///
|
///
|
||||||
@ -95,6 +96,10 @@ public:
|
|||||||
///
|
///
|
||||||
bool protectSpace() const { return protectspace_; }
|
bool protectSpace() const { return protectspace_; }
|
||||||
///
|
///
|
||||||
|
void terminateCommand(bool terminate) { terminate_command_ = terminate; }
|
||||||
|
///
|
||||||
|
bool terminateCommand() const { return terminate_command_; }
|
||||||
|
///
|
||||||
void lastChar(char_type const & c)
|
void lastChar(char_type const & c)
|
||||||
{
|
{
|
||||||
parbreak_ = (!canbreakline_ && c == '\n');
|
parbreak_ = (!canbreakline_ && c == '\n');
|
||||||
@ -111,6 +116,8 @@ private:
|
|||||||
///
|
///
|
||||||
bool protectspace_;
|
bool protectspace_;
|
||||||
///
|
///
|
||||||
|
bool terminate_command_;
|
||||||
|
///
|
||||||
bool parbreak_;
|
bool parbreak_;
|
||||||
///
|
///
|
||||||
char_type lastchar_;
|
char_type lastchar_;
|
||||||
@ -144,14 +151,22 @@ struct SafeBreakLine {
|
|||||||
char n;
|
char n;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Helper structs for terminating a command
|
||||||
|
struct TerminateCommand {
|
||||||
|
char n;
|
||||||
|
};
|
||||||
|
|
||||||
extern BreakLine breakln;
|
extern BreakLine breakln;
|
||||||
extern SafeBreakLine safebreakln;
|
extern SafeBreakLine safebreakln;
|
||||||
|
extern TerminateCommand termcmd;
|
||||||
|
|
||||||
///
|
///
|
||||||
otexstream & operator<<(otexstream &, BreakLine);
|
otexstream & operator<<(otexstream &, BreakLine);
|
||||||
///
|
///
|
||||||
otexstream & operator<<(otexstream &, SafeBreakLine);
|
otexstream & operator<<(otexstream &, SafeBreakLine);
|
||||||
///
|
///
|
||||||
|
otexstream & operator<<(otexstream &, TerminateCommand);
|
||||||
|
///
|
||||||
otexstream & operator<<(otexstream &, odocstream_manip);
|
otexstream & operator<<(otexstream &, odocstream_manip);
|
||||||
///
|
///
|
||||||
otexstream & operator<<(otexstream &, TexString);
|
otexstream & operator<<(otexstream &, TexString);
|
||||||
|
Loading…
Reference in New Issue
Block a user