mirror of https://github.com/KLayout/klayout.git
Adding immediate text scheme to abstract paths: 'text:blabla' will create a 'file' with content 'blabla'
This commit is contained in:
parent
b4c9527347
commit
de052422d8
|
|
@ -397,6 +397,15 @@ InputStream::InputStream (const std::string &abstract_path_in, bool allow_explic
|
|||
memcpy (data_ptr, data.begin ().operator-> (), data.size ());
|
||||
mp_delegate = new InputMemoryStream (data_ptr, data.size (), true);
|
||||
|
||||
} else if (ex.test ("text:")) {
|
||||
|
||||
const char *text = ex.get ();
|
||||
size_t text_len = abstract_path.size () - (text - abstract_path.c_str ());
|
||||
|
||||
char *data_ptr = new char [text_len];
|
||||
memcpy (data_ptr, text, text_len);
|
||||
mp_delegate = new InputMemoryStream (data_ptr, text_len, true);
|
||||
|
||||
} else if (ex.test ("pipe:")) {
|
||||
|
||||
mp_delegate = new InflatingInputPipe (ex.get ());
|
||||
|
|
|
|||
|
|
@ -212,6 +212,48 @@ TEST(DataInputStreamWithSuffix)
|
|||
EXPECT_EQ (is.suffix (), "txt");
|
||||
}
|
||||
|
||||
TEST(ImmediateTextInputStream)
|
||||
{
|
||||
tl::InputStream is ("text:Hello, world!\nWith another line\n");
|
||||
tl::TextInputStream tis (is);
|
||||
EXPECT_EQ (tis.get_line (), "Hello, world!");
|
||||
EXPECT_EQ (tis.line_number (), size_t (1));
|
||||
EXPECT_EQ (tis.get_line (), "With another line");
|
||||
EXPECT_EQ (tis.line_number (), size_t (2));
|
||||
EXPECT_EQ (tis.at_end (), true);
|
||||
|
||||
EXPECT_EQ (is.is_explicit_suffix (), false);
|
||||
EXPECT_EQ (is.suffix (), "");
|
||||
}
|
||||
|
||||
TEST(ImmediateTextInputStreamWithSuffix)
|
||||
{
|
||||
tl::InputStream is ("text:Hello, world!\nWith another line[xyz]");
|
||||
tl::TextInputStream tis (is);
|
||||
EXPECT_EQ (tis.get_line (), "Hello, world!");
|
||||
EXPECT_EQ (tis.line_number (), size_t (1));
|
||||
EXPECT_EQ (tis.get_line (), "With another line");
|
||||
EXPECT_EQ (tis.line_number (), size_t (2));
|
||||
EXPECT_EQ (tis.at_end (), true);
|
||||
|
||||
EXPECT_EQ (is.is_explicit_suffix (), true);
|
||||
EXPECT_EQ (is.suffix (), "xyz");
|
||||
}
|
||||
|
||||
TEST(ImmediateTextInputStreamWithoutExplicitSuffix)
|
||||
{
|
||||
tl::InputStream is ("text:Hello, world!\nWith another line[xyz]", false /*no explicit suffix*/);
|
||||
tl::TextInputStream tis (is);
|
||||
EXPECT_EQ (tis.get_line (), "Hello, world!");
|
||||
EXPECT_EQ (tis.line_number (), size_t (1));
|
||||
EXPECT_EQ (tis.get_line (), "With another line[xyz]");
|
||||
EXPECT_EQ (tis.line_number (), size_t (2));
|
||||
EXPECT_EQ (tis.at_end (), true);
|
||||
|
||||
EXPECT_EQ (is.is_explicit_suffix (), false);
|
||||
EXPECT_EQ (is.suffix (), "");
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue