|
Boost : |
From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-06-02 13:03:07
The attached file contains some predicates that allow using standard
algorithms on character ranges in a locale-aware fashion. For instance
they allow writing the classical ltrim() function (remove all trailing
whitespaces) as:
template <typename stringT>
stringT ltrim(const stringT& s, const std::locale & loc
= std::locale())
{
typedef typename stringT::value_type char_type;
typename stringT::const_iterator it =
std::find_if(
s.begin(), s.end(),
std::not1(is_classified_as<char_type>(std::ctype_base::space,
loc))
);
return stringT(it, s.end());
}
I'm posting them here to have some feedback and ask if there's any
interest for inclusion into boost. They are quite trivial stuff but
IMHO useful enough to have it somewhere in a reusable form :-)
There are some little design details which are not settled yet.
Comments on them are very welcome. In particular:
- is_classified_as<> defaults its template parameter to char, for ease
of use. Objections?
- should is_classified_as::m_ctype be a reference or a non-const
pointer? That has of course to do with whether we want the function
object to be assignable with the compiler-generated operator=().
Thoughts?
Please, Beware that the code is untested. Just checking if there's
interest...
Genny.
begin 644 char_functors.hpp
M#0HO+R!!(&)U;F-H(&]F('1R:79I86P_at_9G5N8W1O<G,@=&\@=7-E('-T86YD
M87)D(&QI8G)A<GD_at_86QG;W)I=&AM<PT*+R\@;VX_at_8VAA<F%C=&5R(')A;F=E
M<RX@*$,I($=E;FYA<F\@4')O=&$@,C`P,PT*+R\-"B\O($QA<W0@;6]D:69I
M960Z(#,Q($UA>2`R,#`S#0H-"@T*+R\@+2TM+2!!1$0_at_24Y#3%5$12!'54%2
M1"`M+2T-"@T*#0HC:6YC;'5D92`\;&]C86QE/@T*(VEN8VQU9&4@/&9U;F-T
M:6]N86P^#0H-"B\O(%%U97-T:6]N<SH-"B\O("`@+2!C:&%R5"`](&-H87(_
M#0HO+R`@("T@<&]I;G1E<B!A<R!M96UB97(_(&]R(')E9C\-"B\O#0IT96UP
M;&%T92`\8VQA<W,@8VAA<E0@/2!C:&%R/@T*8VQA<W,@:7-?8VQA<W-I9FEE
M9%]A<PT*("`Z('!U8FQI8R!S=&0Z.G5N87)Y7V9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F%M92!T<F%I='-4.CIC:&%R7W1Y
M<&4L#0H@("`@("`@("`@("`@("`@("`@("`@("`@("`@8F]O;`T*("`@("`@
M("`@("`@("`@("`@("`@/@T*>PT*<'5B;&EC._at_T*("`@('1Y<&5D968@='EP
M96YA;64@=')A:71S5#HZ8VAA<E]T>7!E(&-H87)?='EP93L-"@T*("`@(&)O
M;VP@;W!E<F%T;W(H*2AC;VYS="!C:&%R7W1Y<&4@)B!C,2P-"B`@("`@("`@
M("`@("`@("`@("`@8V]N<W0_at_8VAA<E]T>7!E("8_at_8S(I(&-O;G-T#0H@("`@
M>R!R971U<FX@=')A:71S5#HZ97$H8S$L(&,R*3L@?0T*#0I].PT*#0HO+R!I
M9&5N=&EC86P@=&\@=&AE(&%B;W9E+"!B=70_at_8F%S960@;VX@:6YT7W1Y<&4-
M"G1E;7!L871E(#QC;&%S<R!T<F%I='-4/@T*8VQA<W,@8VAA<E]I;G1?97%U
M86Q?=&\@.B!P=6)L:6,@<W1D.CIB:6YA<GE?9G5N8W1I;VX\#0H@("`@("`@
M("`@("`@("`@("`@("`@("`@("`@("`@("!T>7!E;F%M92!T<F%I='-4.CII
M;G1?='EP92P-"B`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@('1Y
M<&5N86UE('1R86ET<U0Z.FEN=%]T>7!E+`T*("`@("`@("`@("`@("`@("`@
M("`@("`@("`@("`@("`@8F]O;`T*("`@("`@("`@("`@("`@("`@("`@("`@
M("`^#0I[#0IP=6)L:6,Z#0H@("`@='EP961E9B!T>7!E;F%M92!T<F%I='-4
M.CII;G1?='EP92!I;G1?='EP93L-"@T*("`@(&)O;VP@;W!E<F%T;W(H*2AC
M;VYS="!I;G1?='EP92`F('@Q+`T*("`@("`@("`@("`@("`@("`@("!C;VYS
M="!I;G1?='EP92`F('@R*2!C;VYS=`T*("`@('L@<F5T=7)N('1R86ET<U0Z
M.F5Q7VEN=%]T>7!E*'@Q+"!X,BD[('T-"@T*?3L-"@T*#0H-"B\O($-A;B!A
M;B!I;7!L96UE;G1A=&EO;B!R971U<FX_at_9&EF9F5R96YT('9A;'5E<PT*+R\@
M9G)O;2!D:69F97)E;G0_at_8V%L;',@;V8@=')A:71S5#HZ96]F*"D_#0HO+R!)
M(&1O;B=T(&MN;W<N($EN(&%N>2!C87-E(&ET)W,@<F5Q=6ER960@=&AA=`T*
M+R\@97%?:6YT7W1Y<&4@=V]R:W,@87,@97AP96-T960@*#(Q+C$N,2!486)L
M92`S-RD-"B\O('-O('=E(&-A;B!C86-H92!T:&4@=F%L=64@;V8_at_82!C86QL
M(&EN('1H92!C;VYS=')U8W1O<@T*+R\-"G1E;7!L871E(#QT>7!E;F%M92!T
M<F%I='-4/@T*8VQA<W,@:7-?96]F('L-"B!P=6)L:6,Z#0H@("`@('1Y<&5D
M968@='EP96YA;64@=')A:71S5#HZ:6YT7W1Y<&4@:6YT7W1Y<&4[#0H-"B`@
M("`@:7-?96]F*"D-"B`@("`@("`Z(&U?96]F*'1R86ET<U0Z.F5O9B_at_I*0T*
M("`@("![?0T*#0H@("`@(&)O;VP@;W!E<F%T;W(H*2AC;VYS="!I;G1?='EP
M928_at_8RD@8V]N<W0@>PT*("`@("`@("`@<F5T=7)N('1R86ET<U0Z.F5Q7VEN
M=%]T>7!E*&,L(&U?96]F*3L-"B`@("`@?0T*('!R:79A=&4Z#0H@("`@(&EN
5=%]T>7!E(&U?96]F.PT*#0I].PT*
`
end
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk