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

Archive Download this file

Branches

Tags

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