From 90ddf5bcf1a4cd719a8d5997a9ed3cafc36f1e04 Mon Sep 17 00:00:00 2001
From: Mrbytes <eguervos@msn.com>
Date: Thu, 13 Sep 2012 18:13:20 -0400
Subject: [PATCH] EmptyRepositoryPage_es.html: up-to date with the last changes

---
 src/com/gitblit/utils/StringUtils.java |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/com/gitblit/utils/StringUtils.java b/src/com/gitblit/utils/StringUtils.java
index c13be8a..e440790 100644
--- a/src/com/gitblit/utils/StringUtils.java
+++ b/src/com/gitblit/utils/StringUtils.java
@@ -15,6 +15,7 @@
  */
 package com.gitblit.utils;
 
+import java.io.ByteArrayOutputStream;
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
@@ -78,7 +79,7 @@
 	 * @return plain text escaped for html
 	 */
 	public static String escapeForHtml(String inStr, boolean changeSpace) {
-		StringBuffer retStr = new StringBuffer();
+		StringBuilder retStr = new StringBuilder();
 		int i = 0;
 		while (i < inStr.length()) {
 			if (inStr.charAt(i) == '&') {
@@ -119,7 +120,7 @@
 	 * @return properly escaped url
 	 */
 	public static String encodeURL(String inStr) {
-		StringBuffer retStr = new StringBuffer();
+		StringBuilder retStr = new StringBuilder();
 		int i = 0;
 		while (i < inStr.length()) {
 			if (inStr.charAt(i) == '/') {
@@ -624,4 +625,39 @@
 		}
 		return url;
 	}
+	
+	/**
+	 * Converts a string with \nnn sequences into a UTF-8 encoded string.
+	 * @param input
+	 * @return
+	 */
+	public static String convertOctal(String input) {
+		try {
+			ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+			Pattern p = Pattern.compile("(\\\\\\d{3})");
+			Matcher m = p.matcher(input);
+			int i = 0;
+			while (m.find()) {
+				bytes.write(input.substring(i, m.start()).getBytes("UTF-8"));
+				// replace octal encoded value
+				// strip leading \ character
+				String oct = m.group().substring(1);
+				bytes.write(Integer.parseInt(oct, 8));
+				i = m.end();			
+			}
+			if (bytes.size() == 0) {
+				// no octal matches
+				return input;
+			} else {
+				if (i < input.length()) {
+					// add remainder of string
+					bytes.write(input.substring(i).getBytes("UTF-8"));
+				}
+			}
+			return bytes.toString("UTF-8");
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return input;
+	}
 }
\ No newline at end of file

--
Gitblit v1.9.1