Do not include a dot/slash/colon/questionmark/semicolon after URLs into the link...
[TortoiseGit.git] / src / Git / gittype.h
blobfabb61aeb9e964d29c67af1f53fdd4283e283fd0
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
21 #include "GitHash.h"
23 enum
25 TGIT_GIT_SUCCESS=0,
26 TGIT_GIT_ERROR_OPEN_PIP,
27 TGIT_GIT_ERROR_CREATE_PROCESS,
28 TGIT_GIT_ERROR_GET_EXIT_CODE
31 class CGitByteArray:public std::vector<BYTE>
33 public:
34 CGitByteArray(){ m_critSec.Init(); }
35 CComCriticalSection m_critSec;
37 int find(BYTE data, int start = 0) const
39 for (unsigned int i = start; i < size(); ++i)
40 if( at(i) == data )
41 return i;
42 return -1;
44 int RevertFind(BYTE data, int start = -1) const
46 if(start == -1)
47 start = (int)size() - 1;
49 if(start<0)
50 return -1;
52 for(int i=start; i>=0;i--)
53 if( at(i) == data )
54 return i;
55 return -1;
57 int findNextString(int start = 0) const
59 int pos=start;
62 pos=find(0,pos);
63 if(pos >= 0)
64 ++pos;
65 else
66 break;
68 if (pos >= (int)size())
69 return -1;
71 }while(at(pos)==0);
73 return pos;
75 int findData(const BYTE* dataToFind, size_t dataSize, int start = 0) const
77 //Pre checks
78 if(empty())
79 return -1;
80 if(dataSize==0)
81 return 0;
82 if(dataSize>size()-start)
83 return -1;//Data to find is greater then data to search in. No match
85 //Initialize
86 const BYTE* pos=&*(begin()+start);
87 const BYTE* dataEnd=&*(begin()+(size()-dataSize) );++dataEnd;//Set end one step after last place to search
88 if(pos>=dataEnd)
89 return -1;//Started over end. Return not found
90 BYTE firstByte=dataToFind[0];
91 while(pos<dataEnd)
93 //memchr for first character
94 const BYTE* found=(const BYTE*)memchr(pos,firstByte,dataEnd-pos);
95 if(found==NULL)
96 return -1;//Not found
97 //check rest of characters
98 if(memcmp(found,dataToFind,dataSize)==0)
99 return (int)(found-&*begin());//Match. Return position.
100 //No match. Set position on next byte and continue search
101 pos=found+1;
103 return -1;
105 int append( std::vector<BYTE> &v,int start=0,int end=-1)
107 if(end<0)
108 end = (int)v.size();
109 for (int i = start; i < end; ++i)
110 this->push_back(v[i]);
111 return 0;
113 int append(const BYTE* data, size_t dataSize)
115 size_t oldsize=size();
116 resize(oldsize+dataSize);
117 memcpy(&*(begin()+oldsize),data,dataSize);
118 return 0;
121 typedef std::vector<CString> STRING_VECTOR;
122 typedef std::map<CGitHash, STRING_VECTOR> MAP_HASH_NAME;
123 typedef CGitByteArray BYTE_VECTOR;