<?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[Bitte um Feedback zu Filepath Parse Funktion]]></title><description><![CDATA[<p>Hi,</p>
<p>es wäre schön wenn Ihr Feedback zu meiner Funktion geben könntet.<br />
Was kann ich besser machen, was würdet ihr anders machen?</p>
<p>Ich habe zuerst versucht const_reverse iteratoren zu benutzen und den Filenamen damit abzuschneiden allerdings habe ich es nicht hingekriegt.<br />
Das das schneller ist als mit der herkömlichen Methode.</p>
<p>Ich brauche wenn ich reverse iteratoren benutzen will eine zusätzliche For-Schleife um den Namen wieder zurückumzuwandeln und ich schubse die Buchstaben dann manuell rein.</p>
<p>Vielleicht hat ja noch jemand eine Idee wie das abschneiden des Filenamens mit reverse iteratoren richtig zu implementieren ist.<br />
Ich stell mich da ein wenig zu doof an.</p>
<p>Der reverse Iterator Ansatz:</p>
<pre><code>char Mgr::filename_parse_result(const std::string &amp; filepath) {

    string::const_reverse_iterator cr_it;

    string work_reverse_string;
    work_reverse_string.reserve(15);

    string work_string;
    work_string.reserve(15);  

    for (cr_it = filepath.crbegin(); cr_it != filepath.crend(); ++cr_it) {
        if (*cr_it == '\\') 
            break;

        work_reverse_string += *cr_it;
    }
    for (cr_it = work_reverse_string.crbegin(); cr_it != work_reverse_string.crend(); ++cr_it) {
        work_string += *cr_it;
    }

    if (work_string.find(&quot;resolve&quot;) != string::npos)
        return 'B';
    else {
        for (string::const_iterator it = work_string.cbegin(); it != work_string.cend(); ++it) {
            if (*it &gt;= '0' &amp;&amp; *it &lt;= '9')
                return 'B';
            else return 'A';
        }
    }
}
</code></pre>
<p>Hier erst mal das Problem:</p>
<p>Ich möchte 40 Filename parsen.(40 Filenames)<br />
Problem:<br />
4 Arten von Filenames und ich muss sie entweder in den einen oder anderen Korb werfen.</p>
<p>1. Korb1:<br />
Syntax Fileart 1: &quot;foo_bar_foo.txt&quot;<br />
Syntax Fileart 2: &quot;foo_foo_bar.html&quot;</p>
<p>2. Korb2:<br />
Syntax Fileart 3: &quot;1033.txt&quot;<br />
Syntax Fileart 4: &quot;bar_foo_bar.html.resolve&quot;</p>
<p>Die Funktion bekommt einen relativen Pfad e.g. &quot;.\foo\foo_bar_foo.txt&quot;</p>
<pre><code>char Mgr::filename_parse_result_loesung_3(const std::string &amp; filepath) {

    string::const_iterator c_it;
    string::const_iterator it_begin;

    string work_string;
    work_string.reserve(15);  

    for (c_it = filepath.cbegin(); c_it != filepath.cend(); ++c_it) {
        if (*c_it == '\\')
            it_begin = c_it+1;
    }

    work_string.assign(it_begin, filepath.end());

    if (work_string.find(&quot;resolve&quot;) != string::npos)
        return 'B';
    else {
        for (string::const_iterator it = work_string.cbegin(); it != work_string.cend(); ++it) {
            if (*it &gt;= '0' &amp;&amp; *it &lt;= '9')
                return 'B';
            else return 'A';
        }
    }
}
</code></pre>
<p>Ich hatte auch noch eine dritte Lösung die mir vom Lesen her ein wenig besser gefällt, allerdings ein wenig langsamer ist.</p>
<pre><code>char Mgr::filename_parse_result_loesung_2(const std::string &amp; filepath) {

    string filename;
    filename.reserve(15);

    size_t begin = filepath.find_last_of(&quot;\\&quot;)+1;

    filename = std::move(filepath.substr(begin, filepath.length() - begin));

    if (filename.find(&quot;resolve&quot;) != string::npos)
        return 'B';
    else {
        for (string::const_iterator it = filename.cbegin(); it != filename.cend(); ++it) {
            if (*it &gt;= '0' &amp;&amp; *it &lt;= '9')
                return 'B';
            else return 'A';

        }
    }
}
</code></pre>
<p>Vielen Dank schon mal für Feedback.</p>
<p>Gruß<br />
Christian</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/326886/bitte-um-feedback-zu-filepath-parse-funktion</link><generator>RSS for Node</generator><lastBuildDate>Tue, 26 May 2026 04:35:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/326886.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 12 Jul 2014 13:55:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bitte um Feedback zu Filepath Parse Funktion on Sat, 12 Jul 2014 14:48:27 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>es wäre schön wenn Ihr Feedback zu meiner Funktion geben könntet.<br />
Was kann ich besser machen, was würdet ihr anders machen?</p>
<p>Ich habe zuerst versucht const_reverse iteratoren zu benutzen und den Filenamen damit abzuschneiden allerdings habe ich es nicht hingekriegt.<br />
Das das schneller ist als mit der herkömlichen Methode.</p>
<p>Ich brauche wenn ich reverse iteratoren benutzen will eine zusätzliche For-Schleife um den Namen wieder zurückumzuwandeln und ich schubse die Buchstaben dann manuell rein.</p>
<p>Vielleicht hat ja noch jemand eine Idee wie das abschneiden des Filenamens mit reverse iteratoren richtig zu implementieren ist.<br />
Ich stell mich da ein wenig zu doof an.</p>
<p>Der reverse Iterator Ansatz:</p>
<pre><code>char Mgr::filename_parse_result(const std::string &amp; filepath) {

    string::const_reverse_iterator cr_it;

    string work_reverse_string;
    work_reverse_string.reserve(15);

    string work_string;
    work_string.reserve(15);  

    for (cr_it = filepath.crbegin(); cr_it != filepath.crend(); ++cr_it) {
        if (*cr_it == '\\') 
            break;

        work_reverse_string += *cr_it;
    }
    for (cr_it = work_reverse_string.crbegin(); cr_it != work_reverse_string.crend(); ++cr_it) {
        work_string += *cr_it;
    }

    if (work_string.find(&quot;resolve&quot;) != string::npos)
        return 'B';
    else {
        for (string::const_iterator it = work_string.cbegin(); it != work_string.cend(); ++it) {
            if (*it &gt;= '0' &amp;&amp; *it &lt;= '9')
                return 'B';
            else return 'A';
        }
    }
}
</code></pre>
<p>Hier erst mal das Problem:</p>
<p>Ich möchte 40 Filename parsen.(40 Filenames)<br />
Problem:<br />
4 Arten von Filenames und ich muss sie entweder in den einen oder anderen Korb werfen.</p>
<p>1. Korb1:<br />
Syntax Fileart 1: &quot;foo_bar_foo.txt&quot;<br />
Syntax Fileart 2: &quot;foo_foo_bar.html&quot;</p>
<p>2. Korb2:<br />
Syntax Fileart 3: &quot;1033.txt&quot;<br />
Syntax Fileart 4: &quot;bar_foo_bar.html.resolve&quot;</p>
<p>Die Funktion bekommt einen relativen Pfad e.g. &quot;.\foo\foo_bar_foo.txt&quot;</p>
<pre><code>char Mgr::filename_parse_result_loesung_3(const std::string &amp; filepath) {

    string::const_iterator c_it;
    string::const_iterator it_begin;

    string work_string;
    work_string.reserve(15);  

    for (c_it = filepath.cbegin(); c_it != filepath.cend(); ++c_it) {
        if (*c_it == '\\')
            it_begin = c_it+1;
    }

    work_string.assign(it_begin, filepath.end());

    if (work_string.find(&quot;resolve&quot;) != string::npos)
        return 'B';
    else {
        for (string::const_iterator it = work_string.cbegin(); it != work_string.cend(); ++it) {
            if (*it &gt;= '0' &amp;&amp; *it &lt;= '9')
                return 'B';
            else return 'A';
        }
    }
}
</code></pre>
<p>Ich hatte auch noch eine dritte Lösung die mir vom Lesen her ein wenig besser gefällt, allerdings ein wenig langsamer ist.</p>
<pre><code>char Mgr::filename_parse_result_loesung_2(const std::string &amp; filepath) {

    string filename;
    filename.reserve(15);

    size_t begin = filepath.find_last_of(&quot;\\&quot;)+1;

    filename = std::move(filepath.substr(begin, filepath.length() - begin));

    if (filename.find(&quot;resolve&quot;) != string::npos)
        return 'B';
    else {
        for (string::const_iterator it = filename.cbegin(); it != filename.cend(); ++it) {
            if (*it &gt;= '0' &amp;&amp; *it &lt;= '9')
                return 'B';
            else return 'A';

        }
    }
}
</code></pre>
<p>Vielen Dank schon mal für Feedback.</p>
<p>Gruß<br />
Christian</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408298</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408298</guid><dc:creator><![CDATA[chp++]]></dc:creator><pubDate>Sat, 12 Jul 2014 14:48:27 GMT</pubDate></item><item><title><![CDATA[Reply to Bitte um Feedback zu Filepath Parse Funktion on Sat, 12 Jul 2014 15:54:00 GMT]]></title><description><![CDATA[<pre><code>filename = std::move(filepath.substr(begin, filepath.length() - begin));
</code></pre>
<p><s>Da passt [c]erase[/c] viel eher. (Willst du damit gleichzeitig noch ein [c]shrink_to_fit[/c] erzwingen? Wozu?)</s></p>
<pre><code>for (cr_it = work_reverse_string.crbegin(); cr_it != work_reverse_string.crend(); ++cr_it) {
        work_string += *cr_it;
    }
</code></pre>
<p><code>append</code> .</p>
<blockquote>
<p>4 Arten von Filenames und ich muss sie entweder in den einen oder anderen Korb werfen.</p>
</blockquote>
<p><strong>Und wie genau sind die definiert?</strong> .hmtl und .txt - oder html.resolve und nur Zahlen im Dateinamen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408304</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408304</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sat, 12 Jul 2014 15:54:00 GMT</pubDate></item><item><title><![CDATA[Reply to Bitte um Feedback zu Filepath Parse Funktion on Sat, 12 Jul 2014 15:42:24 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<pre><code>filename = std::move(filepath.substr(begin, filepath.length() - begin));
</code></pre>
<p>Da passt <code>erase</code> viel eher. (Willst du damit gleichzeitig noch ein <code>shrink_to_fit</code> erzwingen? Wozu?)</p>
</blockquote>
<p>Das versteh ich nicht so ganz.<br />
Du meinst, dass ich den Filepfad von den anderen Zeichen säubere?<br />
Das würde nicht funktionieren da der FIlepath nicht verändert werden darf, da ich damit später noch die Datei öffne, deswegen ist der const.<br />
Ich müsste ansonsten den Filepath per Value übergeben.</p>
<p>Ich dachte mir eine move Operation eines kleinen strings ist besser als eine Call by Value Übergabe eines langen Strings.</p>
<p>Arcoth schrieb:</p>
<blockquote>
<pre><code>for (cr_it = work_reverse_string.crbegin(); cr_it != work_reverse_string.crend(); ++cr_it) {
        work_string += *cr_it;
    }
</code></pre>
<p><code>append</code> .</p>
</blockquote>
<p>Ich dachte += operator und append seien das selbe oder wie meinst du das?</p>
<p>Arcoth schrieb:</p>
<blockquote>
<p><strong>Und wie genau sind die definiert?</strong> .hmtl und .txt - oder html.resolve und nur Zahlen im Dateinamen?</p>
</blockquote>
<p>Das ist die Definition:</p>
<p>Fileart 1: hat zusammenhängenden alphabetischen Text mit .txt Endung:<br />
Syntax Fileart 1: &quot;foo_bar_foo.txt&quot;</p>
<p>Fileart 2: hat zusammenhängenden alphabetischen Text mit .html Endung:<br />
Syntax Fileart 2: &quot;foo_foo_bar.html&quot;</p>
<p>Fileart 3: hat zusammängenden numerischen Text mit *.txt Endung<br />
Syntax Fileart 3: &quot;1033.txt&quot;</p>
<p>Fileart 4 hat: zusammenhängenden alpabetischen Text mit .html.resolve Endung<br />
Syntax Fileart 4: &quot;bar_foo_bar.html.resolve&quot;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408307</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408307</guid><dc:creator><![CDATA[chp++]]></dc:creator><pubDate>Sat, 12 Jul 2014 15:42:24 GMT</pubDate></item><item><title><![CDATA[Reply to Bitte um Feedback zu Filepath Parse Funktion on Sat, 12 Jul 2014 15:45:57 GMT]]></title><description><![CDATA[<p>Mein Fehler - ich habe fälschlicherweise <code>filepath</code> = <code>filename</code> gelesen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Zum <code>+=</code> und<a href="http://en.cppreference.com/w/cpp/string/basic_string/append" rel="nofollow"> <code>append</code> </a>(klick mal den Link an, dann siehst du die Unterschiede):</p>
<pre><code>work_string.append( work_reverse_string.crbegin(), work_reverse_string.crend() );
</code></pre>
<p>sollte es tun.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408308</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408308</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sat, 12 Jul 2014 15:45:57 GMT</pubDate></item><item><title><![CDATA[Reply to Bitte um Feedback zu Filepath Parse Funktion on Sat, 12 Jul 2014 16:51:13 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Zum <code>+=</code> und<a href="http://en.cppreference.com/w/cpp/string/basic_string/append" rel="nofollow"> <code>append</code> </a>(klick mal den Link an, dann siehst du die Unterschiede):</p>
<pre><code>work_string.append( work_reverse_string.crbegin(), work_reverse_string.crend() );
</code></pre>
<p>sollte es tun.</p>
</blockquote>
<p>EDIT: Visual Studio scheint bei der Messung Probleme zu machen.<br />
Ich bekomm ganz andere Ergebnisse, wenn ich die release exe gleich aus dem Verzeichnis starte: Funktionsaufruf 10.000.000</p>
<p>Das sind die Ergebnise mit Release Exe aus Folder ohne VS Beteiligung</p>
<p>reverse (+=) = 7053ms - 7120ms<br />
reverse (Append) = 6931ms - 7072ms</p>
<p>find_last_of = 3205ms - 3236ms<br />
Iterator = 3102ms - 3126ms</p>
<p>Die Zeile sieht mit Append auf jedenfall schöner aus, danke.<br />
Allerdings egal wie man es dreht und wendet mit dem von links nach rechts wandern bin ich schneller als von rechts nach links wandern.</p>
<p>Gibt es einen weg reverse Iteratoren zu benutzen ohne die Buchstaben dann wieder von rechts nach links zu drehen? Oder sind für diesen Anwendungsfall reverse Iteratoren nicht geeignet?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408311</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408311</guid><dc:creator><![CDATA[chp++]]></dc:creator><pubDate>Sat, 12 Jul 2014 16:51:13 GMT</pubDate></item><item><title><![CDATA[Reply to Bitte um Feedback zu Filepath Parse Funktion on Sat, 12 Jul 2014 17:59:04 GMT]]></title><description><![CDATA[<p>chp++ schrieb:</p>
<blockquote>
<p>EDIT: Visual Studio scheint bei der Messung Probleme zu machen.<br />
Ich bekomm ganz andere Ergebnisse, wenn ich die release exe gleich aus dem Verzeichnis starte: Funktionsaufruf 10.000.000</p>
</blockquote>
<p>Ja, das ist so.<br />
Macht bei bestimmten Sachen sogar nen Unterschied ob man ein Programm mit &quot;Start without Debugging&quot; aus VS startet, oder es direkt über den Explorer/TaskManager/cmd.exe/... startet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2408318</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2408318</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sat, 12 Jul 2014 17:59:04 GMT</pubDate></item></channel></rss>