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

Archive Download this file

Branches

Tags

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