New paper: N3593, std::split(): An Algorithm for Splitting Strings -- Greg Miller

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3593

Date: 2013-03-13

std::split(): An Algorithm for Splitting Strings

by Greg Miller

Excerpt:

Splitting strings into substrings is a common task in many applications. When the need arises in C++, programmers must search for an existing solution or write one of their own. A typical solution might look like the following:

    std::vector<std::string> my_split(const std::string& text, const std::string& delimiter);

A straightforward implementation of the above function would likely use std::string::find or std::string::find_first_of to identify substrings and move from one to the next, building the vector to return. This is a fine solution for simple needs, but it is deficient in the following ways:

  • Must be reimplemented by each individual/organization
  • Not adaptable to different types of delimiter, such as regular expressions
  • Not adaptable to different return types, such as std::set<string>

Google developed a flexible and fast string-splitting API to address these deficiencies. The new API has been well received by internal engineers developing serious applications. The rest of this paper describes Google's string splitting API as it might appear as a C++ standard.

This proposal depends on the following proposals:

  • N3609 (std::string_view)
  • N3513 (Range support)

 

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.