[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master fc4057e 3/9: Genericize
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master fc4057e 3/9: Genericize |
Date: |
Wed, 15 Feb 2017 20:26:59 -0500 (EST) |
branch: master
commit fc4057e9c0db586ed1fbfc79f1eb832d30bdaf06
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Genericize
---
facets.cpp | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/facets.cpp b/facets.cpp
index 51abb63..a72bb47 100644
--- a/facets.cpp
+++ b/facets.cpp
@@ -25,8 +25,8 @@
#include <algorithm> // std::copy()
-// Class blank_is_not_whitespace_ctype is intended for extracting
-// std::strings from a stream without stopping at blanks. It is a
+// Class C_is_not_whitespace_ctype is intended for extracting
+// std::strings from a stream without stopping at char <C>. It is a
// derived work based on Dietmar Kuehl's article
// http://groups.google.com/groups?selm=7vpld2%24jj%241%40nnrp1.deja.com
// which bears no copyright notice, as is usual in usenet.
@@ -35,8 +35,8 @@
// http://groups.google.com/groups?selm=3820A76F.3952E808%40ihug.co.nz
// that ' ' can be used as an array index even if type 'char' is
// signed, because 2.2/3 requires it to have a positive value.
-// However, gcc has a warning for 'char' array indexes that doesn't
-// recognize this exception, so a workaround for "[' ']" is used here.
+// The template parameter is specifically unsigned to avoid compiler
+// warnings about [] with a negative index.
//
// GWC modified this class
// in 2004 (see Motivation below)
@@ -66,10 +66,11 @@
namespace
{
- class blank_is_not_whitespace_ctype: public std::ctype<char>
+ template<unsigned char C>
+ class C_is_not_whitespace_ctype: public std::ctype<char>
{
public:
- blank_is_not_whitespace_ctype()
+ C_is_not_whitespace_ctype()
:std::ctype<char>(get_table(), false, 1)
{}
@@ -78,7 +79,7 @@ namespace
{
static std::ctype_base::mask rc[table_size];
std::copy(classic_table(), classic_table() + table_size, rc);
- rc[' '] &= ~std::ctype_base::space;
+ rc[C] &= ~std::ctype_base::space;
return rc;
}
};
@@ -96,6 +97,6 @@ namespace
std::locale const& blank_is_not_whitespace_locale()
{
- return locale_with_facet<blank_is_not_whitespace_ctype>();
+ return locale_with_facet<C_is_not_whitespace_ctype<' '>>();
}
- [lmi-commits] [lmi] master updated (0cfdd92 -> 59797a5), Greg Chicares, 2017/02/15
- [lmi-commits] [lmi] master a352f9e 2/9: Restore original facet get_table() implementation, Greg Chicares, 2017/02/15
- [lmi-commits] [lmi] master da6c8c9 5/9: Do not treat tab as whitespace in UponPasteCensus(), Greg Chicares, 2017/02/15
- [lmi-commits] [lmi] master a16705a 4/9: Add a tab-is-not-ws facet, Greg Chicares, 2017/02/15
- [lmi-commits] [lmi] master 9a78453 7/9: Fix defect introduced 20160517T2303: tests not updated, Greg Chicares, 2017/02/15
- [lmi-commits] [lmi] master 1f9c757 8/9: Make certain unit tests more general, Greg Chicares, 2017/02/15
- [lmi-commits] [lmi] master 4d92a38 6/9: Allow empty strings to be pasted into a census, Greg Chicares, 2017/02/15
- [lmi-commits] [lmi] master fc4057e 3/9: Genericize,
Greg Chicares <=
- [lmi-commits] [lmi] master 59797a5 9/9: Make unit tests pastable into GUI, Greg Chicares, 2017/02/15
- [lmi-commits] [lmi] master 45a1834 1/9: Remove a dead usenet reference, Greg Chicares, 2017/02/15