
Forged Alliance Forever Forums
Moderator: keyser
Combo wrote:Does auto-teams mean auto-balance? If so that would be a nice addition...
ZaphodX wrote:Nice work guys, we all appreciate it
Love the flags, just hope it doesn't encourage euro ping nazis or Brazilian haters.
Xinnony wrote:And is not finished
Edit : For see the changelog : https://bitbucket.org/thepilot/forged-a ... lobby/diff
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int option, sCount, seqCount, spacesPerTab, tabCount;
vector<string> lines;
string convertSpacesToTabs(int spacesPerTab, string str) {
int curSpaceSeq;
string spaces;
// Get a string of spaces of length spacesPerTab
for (int i = 0; i < spacesPerTab; i++) {
spaces += " ";
}
// Try to find a space sequence in the string
curSpaceSeq = str.find(spaces);
while (curSpaceSeq > -1 ) {
str = str.replace(curSpaceSeq, spaces.length(), "\t");
curSpaceSeq = str.find(spaces);
seqCount++;
}
return str;
}
string convertTabsToSpaces(int spacesPerTab, string str) {
int currentTab;
string spaces;
// Get a string of spaces of length spacesPerTab
for (int i = 0; i < spacesPerTab; i++) {
spaces += " ";
}
// Try to find a tab in the string
currentTab = str.find("\t");
// Ensure tab is found, do the replacement
if (tabCount > -1) {
while (currentTab != -1) {
str = str.replace(currentTab, 1, spaces);
currentTab = str.find("\t");
tabCount++;
}
}
return str;
}
string trim(string str) {
int sLoc = str.find_last_of(' ');
int lineSpaceCount = 0;
int origStrLength = str.length();
// If there is a space at the end of str, run the loop:
while (sLoc == str.length() - 1 && sLoc != 0 && sLoc != -1) {
str = str.substr(0, sLoc);
sLoc = str.find_last_of(' ');
lineSpaceCount++;
}
if (sLoc == 0 && lineSpaceCount == origStrLength - 1) {
str = "";
lineSpaceCount++;
}
sCount += lineSpaceCount;
return str;
}
void readFile(char fn[]) {
fstream FI(fn, fstream::in);
string line;
while (FI.good()) {
getline(FI, line);
line = trim(line);
if (option == 1) {
line = convertTabsToSpaces(spacesPerTab, line);
} else if (option == 2) {
line = convertSpacesToTabs(spacesPerTab, line);
} else {
cout << "You must choose option 1 or 2." << endl << "Option was: ";
cout << option << endl;
}
lines.push_back(line);
}
cout << "File " << endl << " " << fn << endl << "read successfully.";
cout << endl;
return;
}
void writeFile(char fn[]) {
fstream FO(fn, fstream::out);
for (vector<string>::iterator i = lines.begin(); i != lines.end(); i++) {
FO << *i << endl;
}
cout << "File" << endl << " " << fn << endl;
cout << "written successfully." << endl;
}
int main() {
char *fn;
string fN;
sCount = 0;
option = 0;
cout << "Enter the number of spaces per tab: ";
cin >> spacesPerTab;
cout << "Select an option:" << endl << " 1-Replace tabs with spaces";
cout << endl << " 2-Replace spaces with tabs" << endl;
cout << "Option: ";
cin >> option;
cout << "Enter a file name to read (can include path): " << endl;
getline(cin, fN);
getline(cin, fN);
fn = (char*)fN.c_str();
readFile(fn);
if (sCount == 0 && tabCount == 0 && seqCount == 0) {
cout << "There were no changes made to your file." << endl;
cout << "You do not need to save a new file!" << endl;
} else {
cout << "Spaces removed: " << sCount << endl;
if (option == 1) {
cout << "Tabs replaced: " << tabCount << endl;
} else if (option == 2) {
cout << "Space sequences replaced: " << seqCount << endl;
}
cout << "End of processing." << endl << endl;
cout << "Enter a file name to write to (can include path): " << endl;
getline(cin, fN);
fn = (char*)fN.c_str();
writeFile(fn);
}
return 0;
}
if (sLoc != -1) {
while (sLoc == str.length() - 1) {
str = str.substr(0, sLoc);
sLoc = str.find_last_of(' ');
sCount++;
}
}
Users browsing this forum: No registered users and 1 guest