[PATCH 1 of 6 A2 series] pathencode: add _lowerencode function

Adrian Buehlmann adrian at cadifra.com
Sat Oct 6 04:52:22 CDT 2012


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1349429535 -7200
# Node ID e6a3e95d852d7187268be2bad92c5d9ec5840bae
# Parent  4f2f0f367ef64a979c68002e8689e28f579c7d07
pathencode: add _lowerencode function

This code was originally published by Bryan O'Sullivan <bryano at fb.com>
on 2012-09-10 as part of a bigger patch, which wasn't included.

(adapted to call 'inset' instead of 'isset', which was renamed in the mean time)

diff --git a/mercurial/pathencode.c b/mercurial/pathencode.c
--- a/mercurial/pathencode.c
+++ b/mercurial/pathencode.c
@@ -178,6 +178,29 @@
 	return newobj;
 }
 
+static Py_ssize_t _lowerencode(char *dest, size_t destsize,
+                               const char *src, Py_ssize_t len)
+{
+	static const uint32_t onebyte[8] = {
+		1, 0x2bfffbfb, 0xe8000001, 0x2fffffff
+	};
+
+	static const uint32_t lower[8] = { 0, 0, 0x7fffffe };
+
+	Py_ssize_t i = 0, destlen = 0;
+
+	while (i < len) {
+		if (inset(onebyte, src[i]))
+			charcopy(dest, &destlen, destsize, src[i++]);
+		else if (inset(lower, src[i]))
+			charcopy(dest, &destlen, destsize, src[i++] + 32);
+		else
+			escape3(dest, &destlen, destsize, src[i++]);
+	}
+
+	return destlen;
+}
+
 static Py_ssize_t _encode(const uint32_t twobytes[8], const uint32_t onebyte[8],
 			  char *dest, Py_ssize_t destlen, size_t destsize,
 			  const char *src, Py_ssize_t len,


More information about the Mercurial-devel mailing list