From 6ff2e90c518113433b3ecf34b8c17d434079a414 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 27 Mar 1992 15:13:31 +0000 Subject: Add function to expand tabs. --- Lib/stringold.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Lib/stringold.py') diff --git a/Lib/stringold.py b/Lib/stringold.py index f7d4af6b1e..cfb977fcc3 100644 --- a/Lib/stringold.py +++ b/Lib/stringold.py @@ -143,3 +143,16 @@ def zfill(x, width): if s[0] in ('-', '+'): sign, s = s[0], s[1:] return sign + '0'*(width-n) + s + +# Expand tabs in a string. +# Doesn't take non-printing chars into account, but does understand \n. +def expandtabs(s, tabsize): + res = line = '' + for c in s: + if c == '\t': + c = ' '*(tabsize - len(line)%tabsize) + line = line + c + if c == '\n': + res = res + line + line = '' + return res + line -- cgit v1.2.1