Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
/*Created by: PiMaster Member Functions: inline const char* c_str() const - return the data of the string as a const c string clear() - clear the contents of the string (no return) insert(const char c,const unsigned pos) - inserts a character at pos (returns new length) insert(const char* str,const unsigned pos) - inserts a c-string at pos (returns new length) insert(const string& str,const unsigned pos) - inserts a string at pos (returns new length) count(const char c) - returns the number of occurrences of c count(const char* str) - returns the number of occurrences of str count(const string& str) - returns the number of occurrences of str replace(const char* str1,const char* str2) - replace all occurrences of str1 with str2 (returns number of occurrences) replace(const string& str1,const char* str2) - replace all occurrences of str1 with str2 (returns number of occurrences) replace(const char* str1,const string& str2) - replace all occurrences of str1 with str2 (returns number of occurrences) replace(const string& str1,const string& str2) - replace all occurrences of str1 with str2 (returns number of occurrences) erase(const unsigned start,const unsigned end) - erase data between start and end (returns new length) find(const char c,unsigned n,unsigned start=0) - returns the position of the nth occurrence of c starting at start find(const char* str,unsigned n,unsigned start=0) - returns the position of the nth occurrence of str starting at start find(const string& str,unsigned n,unsigned start=0) - returns the position of the nth occurrence of str starting at start rfind(const char c,unsigned n,unsigned start) - returns the position of the nth occurrence of c going backwards starting at start rfind(const char* str,unsigned n,unsigned start) - returns the position of the nth occurrence of str going backwards starting at start rfind(const string& str,unsigned n,unsigned start) - returns the position of the nth occurrence of str going backwards starting at start reserve(const unsigned newsize) - request a new maximum size for the string (returns new size) NOTE: If newsize is less than the current size, the reallocation will NOT happen upper() - make all letters in the string uppercase (no return) lower() - make all letters in the string lowercase (no return) length() - returns the length of the string capacity() - returns the capacity of the string (size of the buffer) Member Operators: inline operator char*() - converts the string to a c string inline operator const char*() - converts the string to a const c string inline char& operator[](const int x) - returns the character at index x NOTE: If x is greater than the string length, it will return a reference to stroob inline const char& operator[](const int x) const - returns the const character at index x NOTE: If x is greater than the string length, it will return a reference to stroob string& operator=(const char c) - sets the string equal to c (NULL terminated) (returns the string) string& operator=(const char* str) - sets the string equal to str (returns the string) string& operator=(const string& str) - sets the string equal to str (returns the string) string& operator+=(const char c) - appends c to the string (returns the string) string& operator+=(const char* str) - appends str to the string (returns the string) string& operator+=(cosnt string& str) - appends str to the string (returns the string) Global Operators: bool operator==(const string& str1,const string& str2) - returns if str1 is equal to str2 bool operator==(const string& str1,const char* str2) - returns if str1 is equal to str2 bool operator==(const char* str1,const string& str2) - returns if str1 is equal to str2 bool operator!=(const string& str1,const string& str2) - returns if str1 is not equal to str2 bool operator!=(const string& str1,const char* str2) - returns if str1 is not equal to str2 bool operator!=(const char* str1,const string& str2) - returns if str1 is not equal to str2 bool operator>(const string& str1,const string& str2) - returns if the length of str1 is greater than the length of str2 bool operator>(const string& str1,const char* str2) - returns if the length of str1 is greater than the length of str2 bool operator>(const char* str1,const string& str2) - returns if the length of str1 is greater than the length of str2 bool operator<(const string& str1,const string& str2) - returns if the length of str1 is less than the length of str2 bool operator<(const string& str1,const char* str2) - returns if the length of str1 is less than the length of str2 bool operator<(const char* str1,const string& str2) - returns if the length of str1 is less than the length of str2 bool operator>=(const string& str1,const string& str2) - returns if the length of str1 is greater than or equal to the length of str2 bool operator>=(const string& str1,const char* str2) - returns if the length of str1 is greater than or equal to the length of str2 bool operator>=(const char* str1,const string& str2) - returns if the length of str1 is greater than or equal to the length of str2 bool operator<=(const string& str1,const string& str2) - returns if the length of str1 is less than or equal to the length of str2 bool operator<=(const string& str1,const char* str2) - returns if the length of str1 is less than or equal to the length of str2 bool operator<=(const char* str1,const string& str2) - returns if the length of str1 is less than or equal to the length of str2 */ #pragma once #ifndef PISTRING #define PISTRING #ifndef NULL #define NULL 0 #endif char stroob=0; struct string{ private: //memory related functions //resize the string data array void resizedata(unsigned newsize){ //minimum buffer size if(newsize<minbuffsize){ newsize=minbuffsize;} char* tmp=new char[datasize+newsize]; if(data!=NULL){ memcpy(tmp,data,datalen+1); delete[] data;} data=tmp; datasize+=newsize;} //doesn't check for memory overlapping void* memcpy(void* dst,const void* src,const unsigned len){ if(dst==NULL || src==NULL || len==0){ return NULL;} char* d=(char*)dst; char* s=(char*)src; unsigned n=0; while(n<len){ *d=*s; ++d; ++s; ++n;} return dst;} //does check for memory overlapping void* memmove(void* dst,const void* src,unsigned len){ if(dst==NULL || src==NULL || len==0){ return NULL;} char* d=(char*)dst; char* s=(char*)src; unsigned n=0; //if dst is potentially overlapping src if(d>s){ d+=len; s+=len; while(n<len){ *d=*s; ++d; ++s; ++n;}} else{ while(n<len){ *d=*s; ++d; ++s; ++n;}} return dst;} unsigned strlen(const char* str) const{ unsigned x=0; while(str[x]!=0){ ++x;} return x;} //functions that are called by other functions //count the number of occurrences of str unsigned countstr(const char* str,const unsigned size) const{ unsigned x,pos=0,n=0; while(pos<=datalen){ //check if we found the string for(x=0;x<size && pos<=datalen;++x,++pos){ if(data[pos]!=str[x]){ break;}} if(x==size){ ++n;} else{ ++pos;}} return n;} //replace every occurrence of str1 with str2 a maximum of num times unsigned replacestr(const char* str1,const char* str2,const unsigned size1,const unsigned size2,const unsigned num){ unsigned c=countstr(str1,size1); if(datalen+(size2-size1)*c>datasize){ resizedata(((size2-size1)*c)<<1);} unsigned x,pos=0,n=0; while(pos<=datalen && n<num){ for(x=0;x<size1 && pos<=datalen;++x,++pos){ if(data[pos]!=str1[x]){ break;}} if(x==size1){ memmove(data+pos+size2-size1,data+pos,datalen+size2-size1); memcpy(data+pos-size1,str2,size2); ++n;} else{ ++pos;}} datalen+=(size2-size1)*n; return n;} //find the nth occurrence of str starting at x unsigned findstr(const char* str,const unsigned s,unsigned x,const unsigned n) const{ unsigned pos,c=0; for(x=0;x<datalen;++x){ for(pos=0;pos<s;++pos){ if(data[x+pos]!=str[pos]){ break;}} if(pos==s){ if(c==n){ return x;} else{ ++c;}}} return datalen+1;} //find the nth occurrence of str starting at x going backwards unsigned rfindstr(const char* str,const unsigned s,unsigned x,const unsigned n) const{ unsigned pos,c=0; for(;x<datalen;--x){ for(pos=0;pos<s;++pos){ if(data[x+pos]!=str[pos]){ break;}} if(pos==s){ if(c==n){ return x;} else{ ++c;}} else{ x-=pos;}} return datalen+1;} //constants //maximum unsigned integer const static unsigned maxint=~0; //difference between 'a' and 'A' (used in upper() and lower() functions) const static unsigned aA_diff='a'-'A'; //the maximum buffer size const static unsigned minbuffsize=32; //friends //operators //equal friend bool operator==(const string&,const string&); friend bool operator==(const string&,const char*); friend bool operator==(const char*,const string&); //not equal friend bool operator!=(const string&,const string&); friend bool operator!=(const string&,const char*); friend bool operator!=(const char*,const string&); //greater than friend bool operator>(const string&,const string&); friend bool operator>(const string&,const char*); friend bool operator>(const char*,const string&); //less than friend bool operator<(const string&,const string&); friend bool operator<(const string&,const char*); friend bool operator<(const char*,const string&); //greater than or equal to friend bool operator>=(const string&,const string&); friend bool operator>=(const string&,const char*); friend bool operator>=(const char*,const string&); //less than or equal to friend bool operator<=(const string&,const string&); friend bool operator<=(const string&,const char*); friend bool operator<=(const char*,const string&); protected: //data char* data; unsigned datasize,datalen; public: string(){ data=new char[32]; data[0]=0; datasize=32; datalen=0;} string(const char* str){ unsigned s=strlen(str); data=new char[s+minbuffsize]; memcpy(data,str,s+1); datasize=s+minbuffsize; datalen=s;} string(const string& str){ data=new char[str.datasize]; memcpy(data,str.data,str.datalen+1); datasize=str.datasize; datalen=str.datalen;} ~string(){ delete[] data;} inline operator const char*() const{ return data;} inline const char* c_str() const{ return data;} inline char& operator[](const unsigned x){ if(x>datalen){ return stroob;} return data[x];} inline const char& operator[](const unsigned x) const{ if(x>datalen){ return stroob;} return data[x];} string& operator=(const char c){ if(2>datasize){ resizedata(minbuffsize+1-datasize);} data[0]=c; data[1]=0; datalen=1; return *this;} string& operator=(const char* str){ unsigned s=strlen(str); if(s+1>datasize){ resizedata(s<<1-datasize);} memcpy(data,str,s+1); datalen=s; return *this;} string& operator=(const string& str){ datalen=str.datalen; if(datalen+1>datasize){ resizedata(datalen<<1-datasize);} memcpy(data,str.data,datalen+1); return *this;} string& operator+=(const char c){ if(datalen+2>datasize){ resizedata(minbuffsize);} data[datalen]=c; data[datalen+1]=0; ++datalen; return *this;} string& operator+=(const char* str){ unsigned s=strlen(str); if(datalen+s+1>datasize){ resizedata(s<<1);} memcpy(data+datalen,str,s+1); datalen+=s; return *this;} string& operator+=(const string& str){ if(datalen+str.datalen+1>datasize){ resizedata(str.datalen<<2);} memcpy(data+datalen,str.data,str.datalen+1); datalen+=str.datalen; return *this;} void clear(){ data[0]=0;} unsigned insert(const char c,const unsigned pos){ if(datalen+2>datasize){ resizedata(minbuffsize);} memmove(data+pos+1,data+pos,datalen-pos); data[pos]=c; ++datalen; return datalen;} unsigned insert(const char* str,const unsigned pos){ unsigned s=strlen(str); if(datalen+s+1>datasize){ resizedata(s<<2);} memmove(data+pos+s,data+pos,datalen-pos); memcpy(data+pos,str,s); datalen+=s; return datalen;} unsigned insert(const string& str,const unsigned pos){ if(datalen+str.datalen+1>datasize){ resizedata(str.datalen<<1);} memmove(data+pos+str.datalen,data+pos,datalen-pos); memcpy(data+pos,str.data,str.datalen); datalen+=str.datalen; return datalen;} //count unsigned count(const char c) const{ return countstr(&c,1);} unsigned count(const char* str) const{ return countstr(str,strlen(str));} unsigned count(const string& str) const{ return countstr(str.data,str.datalen);} //replace unsigned replace(const char* str1,const char* str2,unsigned num=maxint){ return replacestr(str1,str2,strlen(str1),strlen(str2),num);} unsigned replace(const string& str1,const char* str2,unsigned num=maxint){ return replacestr(str1.data,str2,str1.datalen,strlen(str2),num);} unsigned replace(const char* str1,const string& str2,unsigned num=maxint){ return replacestr(str1,str2.data,strlen(str1),str2.datalen,num);} unsigned replace(const string& str1,const string& str2,unsigned num=maxint){ return replacestr(str1.data,str2.data,str1.datalen,str2.datalen,num);} //erase unsigned erase(const unsigned start,const unsigned end){ memmove(data+start,data+end,datalen-end+1); datalen-=end-start; return datalen;} //find unsigned find(const char c,unsigned n=0,unsigned start=0) const{ return findstr(&c,1,start,n);} unsigned find(const char* str,unsigned n=0,unsigned start=0) const{ return findstr(str,strlen(str),start,n);} unsigned find(const string& str,unsigned n=0,unsigned start=0) const{ return findstr(str.data,str.datalen,start,n);} //rfind (reverse find) unsigned rfind(const char c,unsigned n=0,unsigned start=maxint) const{ if(start==maxint){ start=datalen;} return rfindstr(&c,1,start,n);} unsigned rfind(const char* str,unsigned n=0,unsigned start=maxint) const{ if(start==maxint){ start=datalen;} return rfindstr(str,strlen(str),start,n);} unsigned rfind(const string& str,unsigned n=0,unsigned start=maxint) const{ if(start==maxint){ start=datalen;} return rfindstr(str,strlen(str),start,n);} //reserve int reserve(const int newsize){ int size=(newsize>datasize?newsize:datasize); char* tmp=new char[size]; memcpy(tmp,data,datalen); delete[] data; data=tmp; datasize=size; return size;} void upper(){ unsigned pos=0; while(pos<=datalen){ if(data[pos]>='a' && data[pos]<='z'){ data[pos]-=aA_diff;} ++pos;}} void lower(){ unsigned pos=0; while(pos<=datalen){ if(data[pos]>='A' && data[pos]<='Z'){ data[pos]+=aA_diff;} ++pos;}} unsigned length() const{ return datalen;} unsigned capacity() const{ return datasize;}}; //I couldn't use the ones defined in the string class, so I made an obscurely named namespace to hide them //(this isn't bad practice, is it?) namespace strexternalfuncs{ bool isequal(const char* str1,const char* str2,const unsigned len1,const unsigned len2){ if(len1!=len2){ return false;} unsigned pos=0; while(pos<len1){ if(str1[pos]!=str2[pos]){ return false;} ++pos;} return true;} unsigned strlen(const char* str){ unsigned x; while(str[x]!=0){ ++x;} return x;}}; //global operators //equal bool operator==(const string& str1,const string& str2){ return strexternalfuncs::isequal(str1.data,str2.data,str1.datalen,str2.datalen);} bool operator==(const string& str1,const char* str2){ return strexternalfuncs::isequal(str1.data,str2,str1.datalen,strexternalfuncs::strlen(str2));} bool operator==(const char* str1,const string& str2){ return strexternalfuncs::isequal(str1,str2.data,strexternalfuncs::strlen(str1),str2.datalen);} //not equal bool operator!=(const string& str1,const string& str2){ return !strexternalfuncs::isequal(str1.data,str2.data,str1.datalen,str2.datalen);} bool operator!=(const string& str1,const char* str2){ return !strexternalfuncs::isequal(str1.data,str2,str1.datalen,strexternalfuncs::strlen(str2));} bool operator!=(const char* str1,const string& str2){ return !strexternalfuncs::isequal(str1,str2.data,strexternalfuncs::strlen(str1),str2.datalen);} //greater than bool operator>(const string& str1,const string& str2){ return str1.datalen>str2.datalen;} bool operator>(const string& str1,const char* str2){ return str1.datalen>strexternalfuncs::strlen(str2);} bool operator>(const char* str1,const string& str2){ return strexternalfuncs::strlen(str1)>str2.datalen;} //less than bool operator<(const string& str1,const string& str2){ return str1.datalen<str2.datalen;} bool operator<(const string& str1,const char* str2){ return str1.datalen<strexternalfuncs::strlen(str2);} bool operator<(const char* str1,const string& str2){ return strexternalfuncs::strlen(str1)<str2.datalen;} //greater than or equal to bool operator>=(const string& str1,const string& str2){ return str1.datalen>=str2.datalen;} bool operator>=(const string& str1,const char* str2){ return str1.datalen>=strexternalfuncs::strlen(str2);} bool operator>=(const char* str1,const string& str2){ return strexternalfuncs::strlen(str1)>=str2.datalen;} //less than or equal to bool operator<=(const string& str1,const string& str2){ return str1.datalen<=str2.datalen;} bool operator<=(const string& str1,const char* str2){ return str1.datalen<=strexternalfuncs::strlen(str2);} bool operator<=(const char* str1,const string& str2){ return strexternalfuncs::strlen(str1)<=str2.datalen;} #endif
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Trading method
CSS | 11 min ago | 0.27 KB
Google Docs - Exploit
24 min ago | 0.27 KB
SwapEngine Bug [build 1.3]
38 min ago | 0.27 KB
This month smells like money
CSS | 51 min ago | 0.27 KB
AI METHODS
7 hours ago | 0.29 KB
Untitled
7 hours ago | 0.29 KB
Untitled
7 hours ago | 0.29 KB
Untitled
7 hours ago | 0.29 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!