Split the URI library across multiple files.

Review URL: https://chromiumcodereview.appspot.com//10383103

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@7543 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
ahe@google.com 2012-05-11 13:40:03 +00:00
parent 8a459c921e
commit e3cad04c02
4 changed files with 64 additions and 26 deletions

View file

@ -4,6 +4,8 @@
#library('uri');
#source('helpers.dart');
/**
* A parsed URI, inspired by Closure's [URI][] class. Implements [RFC-3986][].
* [uri]: http://closure-library.googlecode.com/svn/docs/class_goog_Uri.html
@ -188,27 +190,3 @@ class Uri {
}
}
}
String merge(String base, String reference) {
if (base == "") return "/$reference";
return "${base.substring(0, base.lastIndexOf("/") + 1)}$reference";
}
String removeDotSegments(String path) {
List<String> output = [];
bool appendSlash = false;
for (String segment in path.split("/")) {
appendSlash = false;
if (segment == "..") {
if (!output.isEmpty() &&
((output.length != 1) || (output[0] != ""))) output.removeLast();
appendSlash = true;
} else if ("." == segment) {
appendSlash = true;
} else {
output.add(segment);
}
}
if (appendSlash) output.add("");
return Strings.join(output, "/");
}

View file

@ -111,13 +111,32 @@
'includes': [
'uri_sources.gypi',
],
'variables': {
'uri_dart': '<(SHARED_INTERMEDIATE_DIR)/uri.dart',
},
'actions': [
{
'action_name': 'generate_uri_dart',
'inputs': [
'../tools/concat_library.py',
'<@(_sources)',
],
'outputs': [
'<(uri_dart)',
],
'action': [
'python',
'<@(_inputs)',
'--output', '<(uri_dart)',
],
'message': 'Generating ''<(uri_dart)'' file.'
},
{
'action_name': 'generate_uri_cc',
'inputs': [
'../tools/create_string_literal.py',
'<(builtin_in_cc_file)',
'<@(_sources)',
'<(uri_dart)',
],
'outputs': [
'<(uri_cc_file)',
@ -129,7 +148,7 @@
'--input_cc', '<(builtin_in_cc_file)',
'--include', 'bin/builtin.h',
'--var_name', 'Builtin::uri_source_',
'<@(_sources)',
'<(uri_dart)',
],
'message': 'Generating ''<(uri_cc_file)'' file.'
},

View file

@ -6,5 +6,6 @@
{
'sources': [
'../../lib/uri/uri.dart',
'../../lib/uri/helpers.dart',
],
}

View file

@ -0,0 +1,40 @@
#!/usr/bin/env python
# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
import optparse
import shutil
import sys
def parse_options(argv):
parser = optparse.OptionParser(usage="Usage: %prog [options] files")
parser.add_option("--output",
dest="output",
help="Write output to FILE.",
metavar="FILE")
(options, arguments) = parser.parse_args(argv[1:])
if not arguments:
parser.error("At least one input file must be provided.")
if not options.output:
parser.error("No --output provided.")
return (options, arguments)
def main():
# Print the command that is being run. This is helpful when
# debugging build errors.
sys.stderr.write('%s\n' % ' '.join(sys.argv))
(options, arguments) = parse_options(sys.argv)
tmp_name = '%s.tmp' % options.output
with open(tmp_name, 'w') as output:
for source in arguments:
with open(source, 'r') as inpt:
for line in inpt:
if line.startswith('#source'):
line = '// %s' % line
output.write(line)
shutil.move(tmp_name, options.output)
if __name__ == '__main__':
main()