OSDN Git Service

2e6474d211073fe3a74e83b926d7bedba790029e
[tortoisegit/TortoiseGitJp.git] / src / Git / gittype.h
1 #pragma once\r
2 \r
3 enum\r
4 {\r
5         GIT_SUCCESS=0,\r
6         GIT_ERROR_OPEN_PIP,\r
7         GIT_ERROR_CREATE_PROCESS,\r
8         GIT_ERROR_GET_EXIT_CODE\r
9 };\r
10 \r
11 extern BOOL g_IsWingitDllload;\r
12 \r
13 class CGitByteArray:public std::vector<BYTE>\r
14 {\r
15 public:\r
16         int find(BYTE data,int start=0)\r
17         {\r
18                 for(int i=start;i<size();i++)\r
19                         if( at(i) == data )\r
20                                 return i;\r
21                 return -1;\r
22         }\r
23         int findNextString(int start=0)\r
24         {\r
25                 int pos=start;\r
26                 do\r
27                 {\r
28                         pos=find(0,pos);\r
29                         if(pos >= 0)\r
30                                 pos++;\r
31                         else\r
32                                 break;\r
33 \r
34                         if( pos >= size())\r
35                                 return -1;\r
36 \r
37                 }while(at(pos)==0);\r
38 \r
39                 return pos;\r
40         }\r
41         int findData(const BYTE* dataToFind, size_t dataSize, int start=0)\r
42         {\r
43                 const BYTE* pos=&*begin()+start;\r
44                 const BYTE* dataEnd=&*end()-(dataSize-1);//Set end one step after last place to search\r
45                 if(pos>=dataEnd)\r
46                         return -1;//Started over end. Return not found\r
47                 if(dataSize==0)\r
48                         return start;//No search data. Return current position\r
49                 BYTE firstByte=dataToFind[0];\r
50                 while(pos<dataEnd)\r
51                 {\r
52                         //memchr for first character\r
53                         const BYTE* found=(const BYTE*)memchr(pos,firstByte,dataEnd-pos);\r
54                         if(found==NULL)\r
55                                 return -1;//Not found\r
56                         //check rest of characters\r
57                         if(memcmp(found,dataToFind,dataSize)==0)\r
58                                 return found-&*begin();//Match. Return position.\r
59                         //No match. Set position on next byte and continue search\r
60                         pos=found+1;\r
61                 }\r
62                 return -1;\r
63         }\r
64         int append( std::vector<BYTE> &v,int start=0,int end=-1)\r
65         {\r
66                 if(end<0)\r
67                         end=v.size();\r
68                 for(int i=start;i<end;i++)\r
69                         this->push_back(v[i]);\r
70                 return 0;\r
71         }\r
72         int append(const BYTE* data, size_t dataSize)\r
73         {\r
74                 size_t oldsize=size();\r
75                 resize(oldsize+dataSize);\r
76                 memcpy(&*(begin()+oldsize),data,dataSize);\r
77                 return 0;\r
78         }\r
79 };\r
80 typedef std::vector<CString> STRING_VECTOR;\r
81 typedef std::map<CString, STRING_VECTOR> MAP_HASH_NAME;\r
82 typedef CGitByteArray BYTE_VECTOR;