lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 4e76bba 098/156: Add support for comments to


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 4e76bba 098/156: Add support for comments to the string interpolation function
Date: Tue, 30 Jan 2018 17:22:21 -0500 (EST)

branch: master
commit 4e76bba3c4fa640368fc70fe745d0e657b8a69c0
Author: Vadim Zeitlin <address@hidden>
Commit: Vadim Zeitlin <address@hidden>

    Add support for comments to the string interpolation function
    
    They can be useful to explain why certain things are done in the
    Mustache templates.
---
 interpolate_string.cpp      | 4 ++++
 interpolate_string_test.cpp | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/interpolate_string.cpp b/interpolate_string.cpp
index f6153d1..28f6f4e 100644
--- a/interpolate_string.cpp
+++ b/interpolate_string.cpp
@@ -210,6 +210,10 @@ void do_interpolate_string_in_context
                                 }
                             break;
 
+                        case '!':
+                            // This is a comment, we just ignore it completely.
+                            break;
+
                         default:
                             if(is_active())
                                 {
diff --git a/interpolate_string_test.cpp b/interpolate_string_test.cpp
index 766c20d..a1813bd 100644
--- a/interpolate_string_test.cpp
+++ b/interpolate_string_test.cpp
@@ -44,6 +44,11 @@ int test_main(int, char*[])
     BOOST_TEST_EQUAL( test_interpolate("foo{{bar}}"),     "foobar"  );
     BOOST_TEST_EQUAL( test_interpolate("{{foo}}{{bar}}"), "foobar"  );
 
+    // Comments should be just ignored.
+    BOOST_TEST_EQUAL( test_interpolate("{{! ignore me}}", ""        );
+    BOOST_TEST_EQUAL( test_interpolate("{{! too}}{{x}}",  "x"       );
+    BOOST_TEST_EQUAL( test_interpolate("{{x}}{{!also}}",  "x"       );
+
     // Sections.
     auto const section_test = [](char const* s)
         {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]