Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::regex_...up_classname(3) C++ Standard Libarystd::regex_...up_classname(3)

NAME
       std::regex_traits::lookup_classname  - std::regex_traits::lookup_class-
       name

Synopsis
	  template< class ForwardIt >

	  char_class_type lookup_classname( ForwardIt first,
	  ForwardIt last,

	  bool icase = false ) const;

	  If the character sequence [first, last) represents  the  name	 of  a
       valid character
	  class	in the currently imbued	locale (that is, the string between [:
       and :] in
	  regular  expressions), returns the implementation-defined value rep-
       resenting this
	  character class. Otherwise, returns zero.

	  If the parameter icase is true, the character	class ignores  charac-
       ter case, e.g. the
	  regex	[:lower:] with std::regex_constants::icase generates a call to
	  regex_traits<>::lookup_classname() with [first, last)	indicating the
       string "lower"
	  and  icase  ==  true.	This call returns the same bitmask as the call
       generated by the
	  regex	[:alpha:] with icase ==	false.

	  The following	character classes are always recognized, in both  nar-
       row and wide
	  character  forms,  and  the  classifications returned	(with icase ==
       false) correspond
	  to the matching classifications obtained by the std::ctype facet  of
       the imbued
	  locale, as follows:

	  character class std::ctype classification
	  "alnum"	  std::ctype_base::alnum
	  "alpha"	  std::ctype_base::alpha
	  "blank"	  std::ctype_base::blank
	  "cntrl"	  std::ctype_base::cntrl
	  "digit"	  std::ctype_base::digit
	  "graph"	  std::ctype_base::graph
	  "lower"	  std::ctype_base::lower
	  "print"	  std::ctype_base::print
	  "punct"	  std::ctype_base::punct
	  "space"	  std::ctype_base::space
	  "upper"	  std::ctype_base::upper
	  "xdigit"	  std::ctype_base::xdigit
	  "d"		  std::ctype_base::digit
	  "s"		  std::ctype_base::space
	  "w"		  std::ctype_base::alnum with '_' optionally added

	  The  classification  returned	 for the string	"w" may	be exactly the
       same as "alnum",
	  in which case	isctype() adds '_' explicitly.

	  Additional classifications such as "jdigit" or "jkanji" may be  pro-
       vided by
	  system-supplied  locales  (in	 which	case  they are also accessible
       through std::wctype)

Parameters
	  first, last -	a pair of iterators which determines the  sequence  of
       characters that
			represents a name of a character class
	  icase	       -  if true, ignores the upper/lower case	distinction in
       the character
			classification

Type requirements
	  -
	  ForwardIt must meet the requirements of LegacyForwardIterator.

Return value
	  The bitmask representing the character classification	determined  by
       the given
	  character class, or char_class_type()	if the class is	unknown.

Example
	  demonstraits	a  custom regex_traits implementation of lookup_class-
       name/isctype

       // Run this code

	#include <iostream>
	#include <locale>
	#include <regex>
	#include <cwctype>

	//  This  custom  regex	 traits	 uses  wctype/iswctype	to   implement
       lookup_classname/isctype
	struct wctype_traits : std::regex_traits<wchar_t>
	{
	    using char_class_type = std::wctype_t;
	    template<class It>
	    char_class_type  lookup_classname(It  first,  It last, bool=false)
       const {
		return std::wctype(std::string(first, last).c_str());
	    }
	    bool isctype(wchar_t c, char_class_type f) const {
		return std::iswctype(c,	f);
	    }
	};

	int main()
	{
	    std::locale::global(std::locale("ja_JP.utf8"));
	    std::wcout.sync_with_stdio(false);
	    std::wcout.imbue(std::locale());

	    std::wsmatch m;
	    std::wstring in = L"";
	    // matches all characters (they are	classified as alnum)
	    std::regex_search(in, m, std::wregex(L"([[:alnum:]]+)"));
	    std::wcout << "alnums: " <<	m[1] <<	'\n'; // prints	""
	    // matches only the	katakana
	    std::regex_search(in, m,
			      std::basic_regex<wchar_t,			   wc-
       type_traits>(L"([[:jkata:]]+)"));
	    std::wcout << "katakana: " << m[1] << '\n';	// prints ""
	}

Output:
	alnums:
	katakana:

See also
	  isctype indicates membership in a character class
		  (public member function)
	  wctype   looks up a character	classification category	in the current
       C locale
		  (function)

http://cppreference.com		  2022.07.31	 std::regex_...up_classname(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::regex_traits::lookup_classname&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help