1
0
mirror of https://github.com/google/fonts.git synced 2024-12-26 10:12:06 +03:00
fonts/tools/rangify.py
2016-05-06 13:45:36 -04:00

50 lines
1.2 KiB
Python
Executable File

#!/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