~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/base/source_map.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2013 Google Inc. All Rights Reserved.
2
 
//
3
 
// Licensed under the Apache License, Version 2.0 (the "License");
4
 
// you may not use this file except in compliance with the License.
5
 
// You may obtain a copy of the License at
6
 
//
7
 
//      http://www.apache.org/licenses/LICENSE-2.0
8
 
//
9
 
// Unless required by applicable law or agreed to in writing, software
10
 
// distributed under the License is distributed on an "AS IS" BASIS,
11
 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 
// See the License for the specific language governing permissions and
13
 
// limitations under the License.
14
 
//
15
 
// Author: sligocki@google.com (Shawn Ligocki)
16
 
//
17
 
// Encoder for Source Map Revision 3. Specification and other info:
18
 
// * https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
19
 
// * http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/
20
 
// * http://en.wikipedia.org/wiki/Variable-length_quantity
21
 
 
22
 
#ifndef PAGESPEED_KERNEL_UTIL_SOURCE_MAP_H_
23
 
#define PAGESPEED_KERNEL_UTIL_SOURCE_MAP_H_
24
 
 
25
 
#include <vector>
26
 
 
27
 
#include "pagespeed/kernel/base/basictypes.h"
28
 
#include "pagespeed/kernel/base/string.h"
29
 
#include "pagespeed/kernel/base/string_util.h"
30
 
 
31
 
namespace net_instaweb {
32
 
 
33
 
namespace source_map {
34
 
 
35
 
// Declares a mapping between a line # and column # in generated file
36
 
// with the corresponding source file #, line # and column #.
37
 
struct Mapping {
38
 
  int gen_line;
39
 
  int gen_col;
40
 
 
41
 
  int src_file;
42
 
  int src_line;
43
 
  int src_col;
44
 
 
45
 
  Mapping() : gen_line(0), gen_col(0), src_file(0), src_line(0), src_col(0) {}
46
 
  Mapping(int gen_line_arg, int gen_col_arg,
47
 
          int src_file_arg, int src_line_arg, int src_col_arg)
48
 
      : gen_line(gen_line_arg),
49
 
        gen_col(gen_col_arg),
50
 
        src_file(src_file_arg),
51
 
        src_line(src_line_arg),
52
 
        src_col(src_col_arg) {
53
 
  }
54
 
};
55
 
 
56
 
typedef std::vector<Mapping> MappingVector;
57
 
 
58
 
// Encodes generated_url, source_url and mappings into encoded_source_map
59
 
// which will be the contents of a JSON Source Map v3 file.
60
 
// Bool returned answers question "Did this succeed?"
61
 
bool Encode(StringPiece generated_url,  // optional: "" to ignore.
62
 
            StringPiece source_url,
63
 
            // mappings MUST already be sorted by gen_line and then gen_col.
64
 
            const MappingVector& mappings,
65
 
            GoogleString* encoded_source_map);
66
 
 
67
 
// TODO(sligocki)-maybe: Do we want a decoder as well? Might be nice for
68
 
// testing purposes, then we could throw a lot of random examples at it and
69
 
// make sure they Encode -> Decode back to the original.
70
 
 
71
 
// Internal methods. These should not be called directly. Included here for
72
 
// test visibility.
73
 
 
74
 
// Simply convert val 0-63 into a base64 char.
75
 
char EncodeBase64(int val);
76
 
// Encodes an arbitrary 32-bit integer into VLQ (Variable Length Quantity)
77
 
// base64 (A sequence of base64 chars which use continuation bits to encode
78
 
// arbitrary length values.)
79
 
GoogleString EncodeVlq(int32 val);
80
 
// Encodes mappings into a sequence of ; and , separated VLQ base64 values.
81
 
bool EncodeMappings(const MappingVector& mappings,
82
 
                    GoogleString* result);
83
 
GoogleString PercentEncode(StringPiece url);
84
 
 
85
 
}  // namespace source_map
86
 
 
87
 
}  // namespace net_instaweb
88
 
 
89
 
#endif  // PAGESPEED_KERNEL_UTIL_SOURCE_MAP_H_