monotone

monotone Mtn Source Tree

Root/transforms.hh

1#ifndef __TRANSFORMS_HH__
2#define __TRANSFORMS_HH__
3
4// copyright (C) 2002, 2003 graydon hoare <graydon@pobox.com>
5// all rights reserved.
6// licensed to the public under the terms of the GNU GPL (>= 2)
7// see the file COPYING for details
8
9#include "revision.hh"
10#include "lua.hh"
11#include "manifest.hh"
12#include "vocab.hh"
13
14#include <vector>
15
16// this file contans various sorts of string transformations. each
17// transformation should be self-explanatory from its type signature. see
18// transforms.cc for the implementations (most of which are delegations to
19// crypto++ and librsync)
20
21namespace CryptoPP {
22 class Base64Encoder;
23 class Base64Decoder;
24 class HexEncoder;
25 class HexDecoder;
26 class Gzip;
27 class Gunzip;
28}
29
30template<typename XFM> std::string xform(std::string const &);
31extern template std::string xform<CryptoPP::Base64Encoder>(std::string const &);
32extern template std::string xform<CryptoPP::Base64Decoder>(std::string const &);
33extern template std::string xform<CryptoPP::HexEncoder>(std::string const &);
34extern template std::string xform<CryptoPP::HexDecoder>(std::string const &);
35extern template std::string xform<CryptoPP::Gzip>(std::string const &);
36extern template std::string xform<CryptoPP::Gunzip>(std::string const &);
37
38// base64 encoding
39
40template <typename T>
41void encode_base64(T const & in, base64<T> & out)
42{ out = xform<CryptoPP::Base64Encoder>(in()); }
43
44template <typename T>
45void decode_base64(base64<T> const & in, T & out)
46{ out = xform<CryptoPP::Base64Decoder>(in()); }
47
48
49// hex encoding
50
51std::string uppercase(std::string const & in);
52std::string lowercase(std::string const & in);
53
54std::string encode_hexenc(std::string const & in);
55std::string decode_hexenc(std::string const & in);
56
57template <typename T>
58void decode_hexenc(hexenc<T> const & in, T & out)
59{ out = decode_hexenc(in()); }
60
61template <typename T>
62void encode_hexenc(T const & in, hexenc<T> & out)
63{ out = encode_hexenc(in()); }
64
65
66// gzip
67
68template <typename T>
69void encode_gzip(T const & in, gzip<T> & out)
70{ out = xform<CryptoPP::Gzip>(in()); }
71
72template <typename T>
73void decode_gzip(gzip<T> const & in, T & out)
74{ out = xform<CryptoPP::Gunzip>(in()); }
75
76
77// both at once (this is relatively common)
78
79template <typename T>
80void pack(T const & in, base64< gzip<T> > & out)
81{
82 gzip<T> tmp;
83 encode_gzip(in, tmp);
84 encode_base64(tmp, out);
85}
86
87template <typename T>
88void unpack(base64< gzip<T> > const & in, T & out)
89{
90 gzip<T> tmp;
91 decode_base64(in, tmp);
92 decode_gzip(tmp, out);
93}
94
95
96// diffing and patching
97
98void diff(data const & olddata,
99 data const & newdata,
100 delta & del);
101
102void diff(manifest_map const & oldman,
103 manifest_map const & newman,
104 delta & del);
105
106void patch(data const & olddata,
107 delta const & del,
108 data & newdata);
109
110
111// version (a.k.a. sha1 fingerprint) calculation
112
113void calculate_ident(data const & dat,
114 hexenc<id> & ident);
115
116void calculate_ident(base64< gzip<data> > const & dat,
117 hexenc<id> & ident);
118
119void calculate_ident(file_data const & dat,
120 file_id & ident);
121
122void calculate_ident(manifest_data const & dat,
123 manifest_id & ident);
124
125void calculate_ident(manifest_map const & mm,
126 manifest_id & ident);
127
128void calculate_ident(revision_data const & dat,
129 revision_id & ident);
130
131void calculate_ident(revision_set const & cs,
132 revision_id & ident);
133
134
135// quick streamy variant which doesn't necessarily load the whole file
136
137void calculate_ident(file_path const & file,
138 hexenc<id> & ident,
139 lua_hooks & lua);
140
141void split_into_lines(std::string const & in,
142 std::vector<std::string> & out);
143
144void split_into_lines(std::string const & in,
145 std::string const & encoding,
146 std::vector<std::string> & out);
147
148void join_lines(std::vector<std::string> const & in,
149 std::string & out,
150 std::string const & linesep);
151
152void join_lines(std::vector<std::string> const & in,
153 std::string & out);
154
155void prefix_lines_with(std::string const & prefix,
156 std::string const & lines,
157 std::string & out);
158
159// remove all whitespace
160std::string remove_ws(std::string const & s);
161
162// remove leading and trailing whitespace
163std::string trim_ws(std::string const & s);
164
165// canonicalize base64 encoding
166std::string canonical_base64(std::string const & s);
167
168// charset conversions
169void charset_convert(std::string const & src_charset, std::string const & dst_charset,
170 std::string const & src, std::string & dst);
171void system_to_utf8(external const & system, utf8 & utf);
172void utf8_to_system(utf8 const & utf, external & system);
173void ace_to_utf8(ace const & ac, utf8 & utf);
174void utf8_to_ace(utf8 const & utf, ace & a);
175
176fs::path localized(file_path const & path);
177fs::path localized(local_path const & path);
178fs::path localized(utf8 const & path);
179std::string localized_as_string(file_path const & path);
180
181// specific internal / external conversions for various vocab terms
182void internalize_cert_name(utf8 const & utf, cert_name & c);
183void internalize_cert_name(external const & ext, cert_name & c);
184void externalize_cert_name(cert_name const & c, utf8 & utf);
185void externalize_cert_name(cert_name const & c, external & ext);
186void internalize_rsa_keypair_id(utf8 const & utf, rsa_keypair_id & key);
187void internalize_rsa_keypair_id(external const & ext, rsa_keypair_id & key);
188void externalize_rsa_keypair_id(rsa_keypair_id const & key, utf8 & utf);
189void externalize_rsa_keypair_id(rsa_keypair_id const & key, external & ext);
190void internalize_var_domain(utf8 const & utf, var_domain & d);
191void internalize_var_domain(external const & ext, var_domain & d);
192void externalize_var_domain(var_domain const & d, utf8 & utf);
193void externalize_var_domain(var_domain const & d, external & ext);
194
195// line-ending conversion
196void line_end_convert(std::string const & linesep, std::string const & src, std::string & dst);
197
198
199
200#endif // __TRANSFORMS_HH__

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status