Last active
December 17, 2015 09:29
-
-
Save alexesDev/5587356 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <fstream> | |
| #include <iostream> | |
| #include <locale> | |
| #include <sstream> | |
| class FileModifier | |
| { | |
| std::string mFilename; | |
| public: | |
| FileModifier(const std::string &filename); | |
| ~FileModifier(); | |
| }; | |
| FileModifier::FileModifier(const std::string &filename) : mFilename(filename) | |
| { | |
| } | |
| FileModifier::~FileModifier() | |
| { | |
| std::ifstream in(mFilename.c_str(), std::ios::in); | |
| std::locale locale("ru_RU.utf-8"); | |
| std::string buffer; | |
| if(in) | |
| { | |
| char tempChar; | |
| bool isNumber = false; | |
| bool isFractionDelmiter = false; | |
| unsigned int fractionLength = 0; | |
| while(!in.eof()) | |
| { | |
| in.get(tempChar); | |
| isFractionDelmiter = (isNumber && (tempChar == ',' || tempChar == '.')); | |
| isNumber = (tempChar >= 48 && tempChar <= 57) || isFractionDelmiter; | |
| if(isNumber) | |
| fractionLength++; | |
| if(isFractionDelmiter) | |
| fractionLength = 0; | |
| if(tempChar != ' ' && (!isNumber || fractionLength < 3)) | |
| buffer += std::toupper(tempChar, locale); | |
| } | |
| in.close(); | |
| std::ofstream out(mFilename.c_str(), std::ios::out); | |
| out << buffer; | |
| out.close(); | |
| } | |
| else | |
| std::cerr << "Input file not found."; | |
| } | |
| int main() | |
| { | |
| FileModifier("input.txt"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment