Liste des Groupes | Revenir à cl c |
#include <Windows.h>This doesn't do globbing (expanding non-quoted wildcard filenames into lists of individual filenames).
#include <iostream>
#include <string_view>
using namespace std;
template<typename CharType, typename Consumer>
requires requires( Consumer consumer, basic_string_view<CharType> sv ) { { consumer( sv ) }; }
void Tokenize( basic_string_view<CharType> sv, Consumer consumer )
{
using sv_t = basic_string_view<CharType>;
auto it = sv.begin();
for( ; it != sv.end(); )
{
CharType end;
typename sv_t::iterator tkBegin;
if( *it == '\"' )
{
end = '\"';
tkBegin = ++it;
}
else
{
end = ' ';
tkBegin = it++;
}
for( ; it != sv.end() && *it != end; ++it );
consumer( sv_t( tkBegin, it ) );
if( it != sv.end() ) [[unlikely]]
{
while( ++it != sv.end() && *it == ' ' );
continue;
}
}
}
int main()
{
LPWSTR pCmdLine = GetCommandLineW();
size_t i = 1;
Tokenize( wstring_view( pCmdLine ), [&]( wstring_view sv )
{
wcout << i++ << L": \"" << sv << L"\"" << endl;
} );
}
Les messages affichés proviennent d'usenet.