]> Softwares of Agnibho - anagram.git/blob - validity.hpp
Removed binaries
[anagram.git] / validity.hpp
1 /**********************************************************************
2 * Title: Anagram
3 * Description: Application for finding anagrams of a word
4 * Author: Agnibho Mondal
5 * Website: http://code.agnibho.com/anagram
6 **********************************************************************
7 Copyright (c) 2013-2015 Agnibho Mondal
8 All rights reserved
9 **********************************************************************
10 This file is part of Anagram.
11
12 Anagram is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
16
17 Anagram is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with Anagram. If not, see <http://www.gnu.org/licenses/>.
24 **********************************************************************/
25 #ifndef VALIDITY
26 #define VALIDITY
27
28 /*
29 * Provides a function for checking validity of the word.
30 */
31
32 #include <string> //For string
33 #include <cctype> //For isalpha, isblank
34
35 bool is_valid(std::string word, bool multi){ //Checks the validity of the provided word. Allows multiline if <multi> is true.
36 bool flag=true; //Flag is true by default. Set to false if invalidity is encountered later.
37 if(multi){ //Multi-word
38 for(int i=0; i<word.length(); i++){
39 if(!(isalpha(word[i]) || isblank(word[i]))){ //Multi-word allows space seperated words.
40 flag=false;
41 }
42 }
43 }
44 else{ //Single word
45 for(int i=0; i<word.length(); i++){
46 if(!(isalpha(word[i]))){ //Only alphabetic characters are allowed.
47 flag=false;
48 }
49 }
50 }
51 return flag;
52 }
53
54 #endif //VALIDITY