Deutsch   English   Français   Italiano  
<vbs1om$3jkch$1@raubtier-asyl.eternal-september.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: Command line globber/tokenizer library for C?
Date: Wed, 11 Sep 2024 14:17:33 +0200
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <vbs1om$3jkch$1@raubtier-asyl.eternal-september.org>
References: <lkbjchFebk9U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 Sep 2024 14:17:26 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="a58a4b43cc3412e7e6d63eb94bcf30e2";
	logging-data="3789201"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18iz2cI7sVGt20VCSLOiHc2LOJbZYWByXg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:IcPQx1DxQ3Th9oU1A/wld2dj5UQ=
Content-Language: de-DE
In-Reply-To: <lkbjchFebk9U1@mid.individual.net>
Bytes: 2172

Do you think it would make sense to switch the language ?

#include <Windows.h>
#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;
		} );
}