<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Wie boost::regex befragen: Welches Zeichen ist für neg. Test verantwortlich? Jetzt auch boost::spirit]]></title><description><![CDATA[<p>N'Abend allerseits!</p>
<p>Hat boost::regex die Möglichkeit mir zu sagen an welcher Stelle im String es den ersten Verstoß findet?</p>
<p>Kleines Bsp.:</p>
<p>Regex: &quot;^abcd$&quot;<br />
String: &quot;abed&quot;<br />
Ergebnis: An der dritten Pos. ist die erste Regelverletzung.</p>
<p>Danke und Gruß,<br />
Goran</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/236193/wie-boost-regex-befragen-welches-zeichen-ist-für-neg-test-verantwortlich-jetzt-auch-boost-spirit</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 00:57:44 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/236193.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 11 Mar 2009 22:00:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wie boost::regex befragen: Welches Zeichen ist für neg. Test verantwortlich? Jetzt auch boost::spirit on Thu, 12 Mar 2009 12:33:51 GMT]]></title><description><![CDATA[<p>N'Abend allerseits!</p>
<p>Hat boost::regex die Möglichkeit mir zu sagen an welcher Stelle im String es den ersten Verstoß findet?</p>
<p>Kleines Bsp.:</p>
<p>Regex: &quot;^abcd$&quot;<br />
String: &quot;abed&quot;<br />
Ergebnis: An der dritten Pos. ist die erste Regelverletzung.</p>
<p>Danke und Gruß,<br />
Goran</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678391</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678391</guid><dc:creator><![CDATA[goran]]></dc:creator><pubDate>Thu, 12 Mar 2009 12:33:51 GMT</pubDate></item><item><title><![CDATA[Reply to Wie boost::regex befragen: Welches Zeichen ist für neg. Test verantwortlich? Jetzt auch boost::spirit on Thu, 12 Mar 2009 09:10:01 GMT]]></title><description><![CDATA[<p>Da es bei einem nicht übereinstimmen eines RegExp sich nicht um einen &quot;Regelverstoß&quot; handelt sondern schlicht dass das Muster nicht auf den string passt wirst Du es IMHO mit der boost::regex nicht herausfinden können. Vielleicht wirst Du aber mit <a href="http://www.boost.org/doc/libs/1_38_0/libs/spirit/classic/index.html" rel="nofollow">boost::spirit</a> fündiger. Der parser gibt nach dem parsen eine <a href="http://www.boost.org/doc/libs/1_38_0/libs/spirit/classic/doc/scanner.html" rel="nofollow">parse_info</a> struktur zurück die enthält infos ob es fehl geschlagen ist und an welcher Stelle er aufgehört hat mit parsen.</p>
<p>Gut Schuß<br />
VuuRWerK <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678514</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678514</guid><dc:creator><![CDATA[VuuRWerK]]></dc:creator><pubDate>Thu, 12 Mar 2009 09:10:01 GMT</pubDate></item><item><title><![CDATA[Reply to Wie boost::regex befragen: Welches Zeichen ist für neg. Test verantwortlich? Jetzt auch boost::spirit on Thu, 12 Mar 2009 12:40:06 GMT]]></title><description><![CDATA[<p>Danke VuuRWerK.</p>
<p>Ich habe mich an boost::spirit gemacht. Doch ohne Erfolg <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Hier ein kurzer Versuch der leider nicht das erwünschte Ergebnis bringt:</p>
<pre><code class="language-cpp">#include &lt;boost/spirit.hpp&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;

int main()
{
        using namespace std;
        using namespace boost::spirit;

        // config
        string conf = &quot;Somevar=1234&quot;;

        // variable
        rule&lt;&gt; someVar = strlit&lt;&gt;(&quot;SomeVar&quot;);
        // value
        rule&lt;&gt; someVal = int_p &gt;&gt; 
                         int_p &gt;&gt; 
                         int_p &gt;&gt;
                         int_p;
        // declaration
        rule&lt;&gt; confDec = someVar &gt;&gt;
                         strlit&lt;&gt;(&quot;=&quot;) &gt;&gt;
                         someVal;

        // parsing
        parse_info&lt;&gt; pI = parse(conf.c_str(),confDec);
        if(pI.full)
                cout &lt;&lt; &quot;OK.\n&quot;;

        return 0;
}
</code></pre>
<p>Hat jemand Verbesserungsvorschläge?</p>
<p>Gruß, Goran</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678642</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678642</guid><dc:creator><![CDATA[goran]]></dc:creator><pubDate>Thu, 12 Mar 2009 12:40:06 GMT</pubDate></item><item><title><![CDATA[Reply to Wie boost::regex befragen: Welches Zeichen ist für neg. Test verantwortlich? Jetzt auch boost::spirit on Thu, 12 Mar 2009 12:58:14 GMT]]></title><description><![CDATA[<p>Da möchte ich Dir mal folgendes Tutorial ans herz legen: <a href="http://magazin.c-plusplus.net/artikel/Boost%3A%3ASpirit%20-%20Eine%20Einf%FChrung" rel="nofollow">Klick</a> Da wird Spirit sehr gut anhand eines INI-File Parsers erklärt, denke das geht in die Richtung was Du machen möchtest.</p>
<p>Gut Schuß<br />
VuuRWerK <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678660</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678660</guid><dc:creator><![CDATA[VuuRWerK]]></dc:creator><pubDate>Thu, 12 Mar 2009 12:58:14 GMT</pubDate></item><item><title><![CDATA[Reply to Wie boost::regex befragen: Welches Zeichen ist für neg. Test verantwortlich? Jetzt auch boost::spirit on Thu, 12 Mar 2009 13:03:44 GMT]]></title><description><![CDATA[<p>int_p ist bereits für mehrstellige Zahlen gedacht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678664</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678664</guid><dc:creator><![CDATA[Dasd]]></dc:creator><pubDate>Thu, 12 Mar 2009 13:03:44 GMT</pubDate></item><item><title><![CDATA[Reply to Wie boost::regex befragen: Welches Zeichen ist für neg. Test verantwortlich? Jetzt auch boost::spirit on Thu, 12 Mar 2009 13:23:20 GMT]]></title><description><![CDATA[<p>Danke für eure Hilfe. Ich hatte im obigen Bsp. in Zeile 11 einen Schreibfehler innerhalb des Strings. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> Jetzt geht das Bsp.</p>
<p>Das von VuuRWerK verlinkte Tutorial habe ich mir heute morgen reingezogen. Doch stellt sich mir eine Frage:</p>
<p>Wie kann ich Variablen überprüfen (Variablen aufgebaut wie in meinem Bsp.) wenn ich deren Reihenfolge nicht kenne? Ich möchte dem User nicht vorschreiben in welcher Reihenfolge er die Variablen angibt. Aber er soll sie nur einmal angeben können.</p>
<p>Gruß, Goran</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678685</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678685</guid><dc:creator><![CDATA[goran]]></dc:creator><pubDate>Thu, 12 Mar 2009 13:23:20 GMT</pubDate></item><item><title><![CDATA[Reply to Wie boost::regex befragen: Welches Zeichen ist für neg. Test verantwortlich? Jetzt auch boost::spirit on Thu, 12 Mar 2009 13:27:19 GMT]]></title><description><![CDATA[<p>du kannst den einzelnen parsern semantic actions mitgeben, z.B. eine action die den gerade geparsten Variablennamen in einer Symboltabelle nachschlägt und bei einer wiederholten Deklaration Alarm schlägt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1678689</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1678689</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 12 Mar 2009 13:27:19 GMT</pubDate></item><item><title><![CDATA[Reply to Wie boost::regex befragen: Welches Zeichen ist für neg. Test verantwortlich? Jetzt auch boost::spirit on Sat, 14 Mar 2009 20:30:33 GMT]]></title><description><![CDATA[<p>Hallo, ich habe mich heute wieder an boost::spirit gemacht.</p>
<p>Folgender Code funktioniert:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;boost/spirit.hpp&gt;

using namespace std;
using namespace boost::spirit;

int main()
{
    // rules
    rule&lt;&gt; comment = chlit&lt;&gt;('#') &gt;&gt; *(anychar_p - eol_p) &gt;&gt; eol_p;
    rule&lt;&gt; space = *(space_p | comment);
    rule&lt;&gt; hostName = repeat_p(4)[range&lt;&gt;('a','d')];
    rule&lt;&gt; hostIp   = repeat_p(4)[range&lt;&gt;('1','4')];
    rule&lt;&gt; converter = strlit&lt;&gt;(&quot;converter&quot;) &gt;&gt; space &gt;&gt; strlit&lt;&gt;(&quot;=&quot;)
        &gt;&gt; space &gt;&gt; strlit&lt;&gt;(&quot;\&quot;&quot;) &gt;&gt; hostName &gt;&gt; strlit&lt;&gt;(&quot;\&quot;&quot;)
        &gt;&gt; space;
    rule&lt;&gt; analyser = strlit&lt;&gt;(&quot;analyser&quot;) &gt;&gt; space &gt;&gt; strlit&lt;&gt;(&quot;=&quot;)
        &gt;&gt; space &gt;&gt; strlit&lt;&gt;(&quot;\&quot;&quot;) &gt;&gt; hostIp &gt;&gt; strlit&lt;&gt;(&quot;\&quot;&quot;)
        &gt;&gt; space;
    rule&lt;&gt; conf = space &gt;&gt; repeat_p(2)[converter | analyser] &gt;&gt; space;

    // open file
    ifstream f(&quot;test.conf&quot;);
    if(!f)
    {
        cerr &lt;&lt; &quot;Can't open config file!\n&quot;;
        exit(1);
    }

    // read file
    string s;
    while(f.good())
        getline(f,s,'~');

    // parse
    parse_info&lt;&gt; pi = parse(s.c_str(),conf);
    if(pi.full)
        cout &lt;&lt; &quot;File is OK:\n&quot;;
    else
        cout &lt;&lt; &quot;Can't understand \&quot;Test.conf\&quot; at position &quot;
            &lt;&lt; pi.length &lt;&lt; &quot;. Stopped at:\n&quot; &lt;&lt; pi.stop;

    return 0;
}
</code></pre>
<p>Bei folgender test.conf ist alles OK:</p>
<pre><code>converter =&quot;abcd&quot;

	# bla	

analyser=&quot;1234&quot;
# foo
</code></pre>
<p>Sobald die Datei die def. Regeln verletzt (z.B. indem man aus &quot;1234&quot; &quot;123&quot; macht) beendet sich das Prog. mit einer Statusmeldung. Aber ich bekomme hier folgende Ausgabe:</p>
<blockquote>
<p>Can't understand &quot;test.conf&quot; at position 4294967295. Stopped here:<br />
&quot;<br />
# foo</p>
</blockquote>
<p>Nun ist 4294967295 = 2^32-1. Was bedeutet das? Läuft hier was über? Damit kann ich dem Nutzer nicht sagen wo seine Datei fehlerhaft ist.</p>
<p>Wisst ihr Rat?</p>
<p>Gruß, Goran</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1679999</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1679999</guid><dc:creator><![CDATA[goran]]></dc:creator><pubDate>Sat, 14 Mar 2009 20:30:33 GMT</pubDate></item><item><title><![CDATA[Reply to Wie boost::regex befragen: Welches Zeichen ist für neg. Test verantwortlich? Jetzt auch boost::spirit on Sat, 14 Mar 2009 23:51:17 GMT]]></title><description><![CDATA[<p>Hab' jetzt eine Lösung:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;boost/spirit.hpp&gt;

using namespace std;
using namespace boost::spirit;

int main()
{
    // rules
    rule&lt;&gt; comment = chlit&lt;&gt;('#') &gt;&gt; *(anychar_p - eol_p) &gt;&gt; eol_p;
    rule&lt;&gt; space = *(space_p | comment);
    rule&lt;&gt; hostName = repeat_p(4)[range&lt;&gt;('a','d')];
    rule&lt;&gt; hostIp   = repeat_p(4)[range&lt;&gt;('1','4')];
    rule&lt;&gt; converter = strlit&lt;&gt;(&quot;converter&quot;) &gt;&gt; space &gt;&gt; strlit&lt;&gt;(&quot;=&quot;)
		&gt;&gt; space &gt;&gt; strlit&lt;&gt;(&quot;\&quot;&quot;) &gt;&gt; hostName &gt;&gt; strlit&lt;&gt;(&quot;\&quot;&quot;)
		&gt;&gt; space;
    rule&lt;&gt; analyser = strlit&lt;&gt;(&quot;analyser&quot;) &gt;&gt; space &gt;&gt; strlit&lt;&gt;(&quot;=&quot;)
		&gt;&gt; space &gt;&gt; strlit&lt;&gt;(&quot;\&quot;&quot;) &gt;&gt; hostIp &gt;&gt; strlit&lt;&gt;(&quot;\&quot;&quot;)
		&gt;&gt; space;
    rule&lt;&gt; conf = space &gt;&gt; repeat_p(2)[converter | analyser] &gt;&gt; space;

    // open file
    ifstream f(&quot;test.conf&quot;);
    if(!f)
    {
        cerr &lt;&lt; &quot;Can't open config file!\n&quot;;
        exit(1);
    }

    // read file
    string s;
    while(f.good())
        getline(f,s,'~');
    const char * c = s.c_str();

    // parse
    parse_info&lt;&gt; p = parse(c,conf);
    if(p.full)
        cout &lt;&lt; &quot;File is OK:\n&quot;;
    else
        cout &lt;&lt; &quot;Can't understand \&quot;Test.conf\&quot; at position &quot;
            &lt;&lt; p.stop-s.c_str() &lt;&lt; &quot;.\n&quot;;

    return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1680178</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1680178</guid><dc:creator><![CDATA[goran]]></dc:creator><pubDate>Sat, 14 Mar 2009 23:51:17 GMT</pubDate></item></channel></rss>