Skip to content

Commit

Permalink
lolcat-cc v1.0.1 - see release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
n-ham committed Jan 26, 2022
1 parent 463afcd commit a0d43a1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $ make && sudo make install

## Why?

This `lolcat` clone was mostly to add limited rainbow support for Windows. It seems to be about twice as fast as `lolcat-c` on speed, both of which are an an entirely different league speed-wise compared to the original ruby version.
This `lolcat` clone was mostly to add limited rainbow support for Windows. Plus it was fun to do my own implementation and it's always nice to win "world's fastest" pissing contests.
To benchmark them, an empty directory was filled with 100k files named `x.txt` where `x` goes from `1` to `100000`. From within the directory the following commands were run:
Expand Down
8 changes: 8 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Lolcat-cc Release Notes
------------------

Version 1.0.1 of lolcat-cc
* cleaned up code
* changed math.h header to cmath
* fixed user input being white when using std::cin
* hopefully fixed degree symbol bug
* fixed finding end of special characters with (char)-80
* added in replacing tabs with specified tab width

Version 1.0.0 of lolcat-cc
* added cross-platform c++ implementation of lolcat (limited colour support on Windows)
* added format, gradient, line numbers, powershell colours, tabwidth, version, width and zigzag options
41 changes: 19 additions & 22 deletions lolcat-cc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <cstdio>
#include <fstream>
#include <iostream>
#include <math.h>
#include <cmath>
#include <sstream>
#include <string>
#include <sys/stat.h>
Expand Down Expand Up @@ -144,8 +144,6 @@ size_t width, cWidth;
bool addLineNo = 0, zigzag = 0;
int posGrad = 1;

const std::string arr = "";

int lolcat(std::istream& is)
{
std::string inLine;
Expand Down Expand Up @@ -196,27 +194,17 @@ int lolcat(std::istream& is)
{
if(format)
{
for(size_t j=1; j<4; ++j)
while(inLine[i] == '\t')
{
if(j < 3 && i+width-j < inLine.size() && inLine[i+width-j] == arr[0])
{ //checks for multi-char utf characters
std::cout << colors[color] << inLine.substr(i, width+3-j);
i += width+3-j;
break;
}
else if(i+width-j < inLine.size() && (inLine[i+width-j] == '\xF0' ||
inLine[i+width-j] == '\xE2' ||
inLine[i+width-j] == '\xC2'))
{ //checks for emojis
std::cout << colors[color] << inLine.substr(i, width+4-j);
i += width+4-j;
break;
}
std::cout << std::string(tabWidth, ' ');
++i;
}

//https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
while(i < inLine.size() && ((inLine[i] == '\\' && (!i || inLine[i-1] != '\\')) ||
inLine[i] == '\x0' ||
while(format && i < inLine.size() && ((inLine[i] == '\\' && (!i || inLine[i-1] != '\\')) ||
inLine[i] == '\x0' ||
inLine[i] == '\xB0' || // degree
inLine.substr(i, 2) == "°" || // degree
inLine[i] == '\xF0' || // emojis
inLine[i] == '\xE2' || // emojis
inLine[i] == '\xC2' || // emojis
Expand All @@ -227,12 +215,17 @@ int lolcat(std::istream& is)
inLine[i] == '\u001b')) // unicode
{
int start = i++;
while(i < inLine.size() && inLine[i] != 'm' &&
while(i < inLine.size() && /*inLine[i] != 'm' && */
inLine[i] != -80 &&
inLine[i] != -92 &&
inLine[i] != ' ' &&
inLine[i] != '\n' &&
inLine[i] != '\t')
++i;
std::cout << inLine.substr(start, i-start);

if(inLine[i] == ' ')
std::cout << colors[color];
}
}

Expand All @@ -246,6 +239,10 @@ int lolcat(std::istream& is)
std::cout << colors[color];
}


if(&is == &std::cin)
std::cout << c_white;

std::cout << std::endl;
++lineNo;
}
Expand Down Expand Up @@ -355,7 +352,7 @@ int main(int argc, char ** argv)
else if(param == "-v" || param == "-version")
{
std::stringstream ss;
ss << "v1.0.0" << std::endl;
ss << "v1.0.1" << std::endl;

return lolfilter(ss);
}
Expand Down

0 comments on commit a0d43a1

Please sign in to comment.