dsrc isn't necessary for this repo
[client-tools.git] / src / external / 3rd / library / perforce / include / strops.h
blob00c6e02a6f03aff186a713500b9be6c65d0f1598
1 /*
2 * Copyright 1995, 1996 Perforce Software. All rights reserved.
4 * This file is part of Perforce - the FAST SCM System.
5 */
7 /*
8 * StrOps.h - operations on strings
10 * StrOps - member-less object with static functions
12 * Methods:
14 * StrOps::Caps() - uppercase each character (in place) in a string
15 * StrOps::Dump() - pretty print contents, for debugging
16 * StrOps::Sub() - replace one character with another
17 * StrOps::Expand() - expand a string doing %var% substitutions
18 * StrOps::Expand2() - expand a string doing [%var%|opt] substitutions
19 * StrOps::Indent() - fill by indenting contents of another buffer
20 * StrOps::Replace() - replace all occurences of a string
21 * StrOps::Lines() - break buffer into \r\n or \n separated lines
22 * StrOps::Lower() - lowercase each character (in place) in a string
23 * StrOps::Words() - break buffer into whitespace-separated words
24 * StrOps::OtoX() - turn an octet stream into hex
25 * StrOps::XtoO() - turn hex into an octet stream
26 * StrOps::WildToStr() - turn wildcards into %x escaped string
27 * StrOps::StrToWild() - turn %x escaped string into wildcards.
28 * StrOps::CompatWild() - turn %%d to %d for p4 where compatability.
30 * StrOps::UnpackInt() - extract an integer from front of buffer
31 * StrOps::UnpackIntA() - extract an integer encoded in ascii
32 * StrOps::UnpackChar() - extract a char string from front of buffer
33 * StrOps::UnpackOctet() - extract a byte string from front of buffer
34 * StrOps::UnpackString() - extract a char string from front of buffer
35 * StrOps::UnpackStringA() - extract a char string with length in ascii
37 * StrOps::PackInt() - append a formatted int to buffer
38 * StrOps::PackIntA() - append a formatted int to buffer in ascii
39 * StrOps::PackChar() - append a formatted string to buffer
40 * StrOps::PackOctet() - append byte array to buffer
41 * StrOps::PackString() - append a formatted string to buffer
42 * StrOps::PackStringA() - append a formatted string with len in ascii
45 class StrPtr;
46 class StrRef;
47 class StrBuf;
48 class StrDict;
50 class StrOps {
52 public:
54 // Manipulating
56 static void Caps( StrBuf &o );
57 static void Dump( const StrPtr &o );
58 static void Sub( StrPtr &string, char target, char replacement );
59 static void Expand( StrBuf &o, const StrPtr &s, StrDict &d );
60 static void Expand2( StrBuf &o, const StrPtr &s, StrDict &d );
61 static void Indent( StrBuf &o, const StrPtr &s );
62 static void Replace( StrBuf &o, const StrPtr &i, const StrPtr &s, const StrPtr &r );
63 static int Lines( StrBuf &o, char *vec[], int maxVec );
64 static void Lower( StrBuf &o );
65 static int Words( StrBuf &o, char *vec[], int maxVec );
67 static void OtoX( const StrPtr &octet, StrBuf &hex );
68 static void XtoO( const StrPtr &hex, StrBuf &octet );
69 static void OtoX( const unsigned char *octet, int len, StrBuf &x );
70 static void XtoO( char *x, unsigned char *octet, int octLen );
72 static char OtoX( unsigned char o )
73 { return o >= 10 ? o - 10 + 'A' : o + '0'; }
75 static unsigned char XtoO( char h )
76 { return h - ( h > '9' ? 'A' - 10 : '0' ); }
78 static void WildToStr( const StrPtr &i, StrBuf &o );
79 static void StrToWild( const StrPtr &i, StrBuf &o );
80 static void WildCompat( const StrPtr &i, StrBuf &o );
82 // Marshalling
84 static void PackInt( StrBuf &o, int v );
85 static void PackIntA( StrBuf &o, int v );
86 static void PackChar( StrBuf &o, const char *c, int len );
87 static void PackOctet( StrBuf &o, const StrPtr &s );
88 static void PackString( StrBuf &o, const StrPtr &s );
89 static void PackStringA( StrBuf &o, const StrPtr &s );
91 static int UnpackInt( StrRef &o );
92 static int UnpackIntA( StrRef &o );
93 static void UnpackChar( StrRef &o, char *c, int length );
94 static void UnpackOctet( StrRef &o, const StrPtr &s );
95 static void UnpackString( StrRef &o, StrBuf &s );
96 static void UnpackStringA( StrRef &o, StrBuf &s );
97 static void UnpackString( StrRef &o, StrRef &s );
98 static void UnpackStringA( StrRef &o, StrRef &s );