forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <exception> | ||
#include <iostream> | ||
#include <regex> | ||
#include <string> | ||
|
||
using std::regex; | ||
|
||
int main() | ||
{ | ||
try { | ||
regex r("[[:alnum]+\\.(cpp|cxx|cc)$", regex::icase); | ||
} | ||
catch (std::regex_error e) { | ||
std::cout << e.what() << "\ncode:" << e.code() << std::endl; | ||
} | ||
} | ||
|
||
// output | ||
// Unexpected end of character class. | ||
// code:1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <exception> | ||
#include <iostream> | ||
#include <regex> | ||
#include <string> | ||
|
||
using std::regex; | ||
|
||
//! @check https://en.wikipedia.org/wiki/I_before_E_except_after_C | ||
int main() | ||
{ | ||
try { | ||
regex r("[[:alpha:]]*(cie|[^c]ei)[[:alpha:]]*"); | ||
std::string word; | ||
while (std::cout << "Enter a word, or q to quit: ", std::cin >> word) { | ||
if (word == "q") break; | ||
std::smatch result; | ||
if (std::regex_search(word, result, r)) | ||
std::cout << "Violate the rule: 'i before e except after c'" | ||
<< std::endl; | ||
else | ||
std::cout << word + " is okay." << std::endl; | ||
} | ||
} | ||
catch (std::regex_error e) { | ||
std::cout << e.what() << "\ncode:" << e.code() << std::endl; | ||
} | ||
} | ||
|
||
//! @test | ||
// Enter a word, or q to quit: believe | ||
// believe is okay. | ||
// Enter a word, or q to quit: receive | ||
// receive is okay. | ||
// Enter a word, or q to quit: species | ||
// Violate the rule: 'i before e except after c' | ||
// Enter a word, or q to quit: seize | ||
// Violate the rule: 'i before e except after c' | ||
// Enter a word, or q to quit: q |