Advertisement
Neveles

ifAuthor

Dec 8th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include "BookInformation.h"
  2.  
  3. void ifAuthor(string &book, const unsigned int &nOfStr, unsigned int &index)
  4. {
  5.     // запись имени автора в строку
  6.     unsigned int headIndex = index;
  7.     index = book.find('|');
  8.     string author = book.substr(headIndex, index);
  9.     book[index] = ' ';
  10.  
  11.     cout << "headIndex: " << headIndex << endl << "index: " << index << endl;
  12.     cout << "BOOK: " << book << endl << "STRING: " << author << endl;
  13.  
  14.     // проверка наличия одного(!) пробела
  15.     unsigned int nSpaces = 0;
  16.     for (unsigned int i = 0; i <= author.size(); ++i)
  17.     {
  18.         if (author[i] == ' ')
  19.             ++nSpaces;
  20.         if (nSpaces > 1)
  21.             throw nOfStr;
  22.     }
  23.     if (nSpaces != 1)
  24.         throw nOfStr;
  25.  
  26.     // проверка, что первая буква - прописная
  27.     unsigned int iLetter = headIndex;
  28.     int firstCode = static_cast<int>(author[iLetter]);
  29.     if (!((((firstCode >= -64) && (firstCode <= -33)) || firstCode == -88)))
  30.         throw nOfStr;
  31.  
  32.     // проверка "амилия"
  33.     ++iLetter;
  34.     for (; author[iLetter] != ' '; ++iLetter)
  35.     {
  36.         int codeOfNumber = static_cast<int>(author[iLetter]);
  37.         if (!(((codeOfNumber >= -32) && (codeOfNumber <= -1)) || codeOfNumber == -72))
  38.             throw nOfStr;
  39.     }
  40.     ++iLetter;
  41.  
  42.     int nameInitial = static_cast<int>(author[iLetter]);
  43.     int patronymicInitial = static_cast<int>(author[iLetter + 2]);
  44.     if (!((((nameInitial >= -64) && (nameInitial <= -33)) || nameInitial == -88) &&
  45.     (((patronymicInitial >= -64) && (patronymicInitial <= -33)) || patronymicInitial == -88) &&
  46.     (author[iLetter + 1] == '.') && (author[iLetter + 3] == '.')))
  47.         throw nOfStr;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement