Skip to content

Instantly share code, notes, and snippets.

@alexesDev
Last active December 17, 2015 09:29
Show Gist options
  • Select an option

  • Save alexesDev/5587356 to your computer and use it in GitHub Desktop.

Select an option

Save alexesDev/5587356 to your computer and use it in GitHub Desktop.
#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