mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-24 10:40:48 +00:00
dfe3a7d9fc
Back references in the format string of regex_replace use the syntax $n both in std::regex and in boost::regex for the default format. Boost seems to support the syntax \n in addition, but it is not documented at http://www.boost.org/doc/libs/master/libs/regex/doc/html/boost_regex/format.html. Therefore it is a good idea to use $n also for boost.
49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#include <config.h>
|
|
|
|
#include "../support/debug.h"
|
|
#include "../support/regex.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
using namespace lyx;
|
|
using namespace std;
|
|
|
|
|
|
// This function is unfortunately copied from ../insets/InsetListing.cpp, so we
|
|
// should try to make sure to keep the two in sync.
|
|
string test_ListingsCaption(string const & cap)
|
|
{
|
|
// convert from
|
|
// blah1\label{blah2} blah3
|
|
// to
|
|
// blah1 blah3},label={blah2
|
|
// to form options
|
|
// caption={blah1 blah3},label={blah2}
|
|
//
|
|
// NOTE that } is not allowed in blah2.
|
|
regex const reg("(.*)\\\\label\\{(.*?)\\}(.*)");
|
|
string const new_cap("$1$3},label={$2");
|
|
return regex_replace(cap, reg, new_cap);
|
|
}
|
|
|
|
void test_test_ListingsCaptions()
|
|
{
|
|
cout << test_ListingsCaption("\\label{}") << endl;
|
|
cout << test_ListingsCaption("\\label{blah2}") << endl;
|
|
cout << test_ListingsCaption("\\label{blah2} blah3") << endl;
|
|
cout << test_ListingsCaption("\\label{} blah3") << endl;
|
|
cout << test_ListingsCaption("blah1\\label{}") << endl;
|
|
cout << test_ListingsCaption("blah1\\label{} blah3") << endl;
|
|
cout << test_ListingsCaption("blah1\\label{blah2}") << endl;
|
|
cout << test_ListingsCaption("blah1\\label{blah2} blah3") << endl;
|
|
}
|
|
|
|
|
|
int main(int, char **)
|
|
{
|
|
// Connect lyxerr with cout instead of cerr to catch error output
|
|
lyx::lyxerr.setStream(cout);
|
|
test_test_ListingsCaptions();
|
|
}
|