1
0
mirror of https://github.com/google/fonts.git synced 2024-11-24 01:37:48 +03:00

Add back tool/rangify.py from hg repo

This commit is contained in:
Dave Crossland 2016-05-06 13:45:36 -04:00
parent 22f2e795c2
commit 73aa5f04ee

49
tools/rangify.py Executable file
View File

@ -0,0 +1,49 @@
#!/usr/bin/python
#
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Contributors: Rod Sheeter (rsheeter google com)
#
# Converts a .nam file to a list of ranges.
import sys
import tokenize
if len(sys.argv) != 2:
print "Usage: rangify <nam file>"
sys.exit(1)
def handle_num(type, token, (srow, scol), (erow, ecol), line):
global cps
if type == tokenize.NUMBER:
cps.append(int(token, 16))
cps = []
tokenize.tokenize(open(sys.argv[1]).readline, handle_num)
cps.sort()
seqs = []
seq = (None,)
for cp in cps:
if seq[0] is None:
seq = (cp,cp)
elif seq[1] == cp - 1:
seq = (seq[0], cp)
else:
seqs.append(seq)
seq = (None,)
for seq in seqs:
print seq