summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/regex/test/quick.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/regex/test/quick.cpp
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/regex/test/quick.cpp')
-rw-r--r--src/boost/libs/regex/test/quick.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/boost/libs/regex/test/quick.cpp b/src/boost/libs/regex/test/quick.cpp
new file mode 100644
index 00000000..0598823d
--- /dev/null
+++ b/src/boost/libs/regex/test/quick.cpp
@@ -0,0 +1,55 @@
+
+// Copyright 1998-2002 John Maddock
+// Copyright 2017 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+//
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+
+// See library home page at http://www.boost.org/libs/regex
+
+#include <boost/regex.hpp>
+#include <boost/core/lightweight_test.hpp>
+#include <string>
+
+bool validate_card_format(const std::string& s)
+{
+ static const boost::regex e("(\\d{4}[- ]){3}\\d{4}");
+ return boost::regex_match(s, e);
+}
+
+const boost::regex card_rx("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z");
+const std::string machine_format("\\1\\2\\3\\4");
+const std::string human_format("\\1-\\2-\\3-\\4");
+
+std::string machine_readable_card_number(const std::string& s)
+{
+ return boost::regex_replace(s, card_rx, machine_format, boost::match_default | boost::format_sed);
+}
+
+std::string human_readable_card_number(const std::string& s)
+{
+ return boost::regex_replace(s, card_rx, human_format, boost::match_default | boost::format_sed);
+}
+
+int main()
+{
+ std::string s[ 4 ] = { "0000111122223333", "0000 1111 2222 3333", "0000-1111-2222-3333", "000-1111-2222-3333" };
+
+ BOOST_TEST( !validate_card_format( s[0] ) );
+ BOOST_TEST_EQ( machine_readable_card_number( s[0] ), s[0] );
+ BOOST_TEST_EQ( human_readable_card_number( s[0] ), s[2] );
+
+ BOOST_TEST( validate_card_format( s[1] ) );
+ BOOST_TEST_EQ( machine_readable_card_number( s[1] ), s[0] );
+ BOOST_TEST_EQ( human_readable_card_number( s[1] ), s[2] );
+
+ BOOST_TEST( validate_card_format( s[2] ) );
+ BOOST_TEST_EQ( machine_readable_card_number( s[2] ), s[0] );
+ BOOST_TEST_EQ( human_readable_card_number( s[2] ), s[2] );
+
+ BOOST_TEST( !validate_card_format( s[3] ) );
+
+ return boost::report_errors();
+}