git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: specify charset for commits

From
Uwe Kleine-König <zeisberg@informatik.uni-freiburg.de>
Date
Dec 22, 2006, 15:09 UTC
Message-ID
<20061222150948.GA6005@cepheus>
In-Reply-To
<Pine.LNX.4.63.0612220351520.19693@wbgn013.biozentrum.uni-wuerzburg.de>
Hello Johannes,
Johannes Schindelin wrote:
Show 5 quoted lines
> The problem is: you cannot easily recognize if it is UTF8 or not, 
> programatically. There is a good indicator _against_ UTF8, namely the 
> first byte can _only_ be 0xxxxxxx, 110xxxxx, 1110xxxx, 11110xxx. But there 
> is no _positive_ sign that it is UTF8. For example, many umlauts and other 
> special modifications to letters, stay in the range 0x7f-0xff.

That's not the only indication. Here comes a (Python) function that checks is string s is correctly UTF-8 encoded:

	def is_utf8_str(s):
	  cnt_furtherbytes = 0
	  for c in s:
	    if cnt_furtherbytes > 0:
	      if ord(c) & 0xc0 == 0x80:
		cnt_furtherbytes -= 1
	      else:
		return False
	    else:
	      if ord(c) < 0x80:
		continue
	      elif ord(c) < 0xc0:
	        return False
	      elif ord(c) < 0xe0:
		cnt_furtherbytes = 1
	      elif ord(c) < 0xf0:
		cnt_furtherbytes = 2
	      elif ord(c) < 0xf8:
		cnt_furtherbytes = 3
	      elif ord(c) < 0xfc:
		cnt_furtherbytes = 4
	      elif ord(c) < 0xfe:
		cnt_furtherbytes = 5
	      else:
		return False
	  return True

An UTF-8 character is either one byte long with the msb 0 or a sequence starting with a value between 0xc0 and 0xfd (inclusive) and depending on that first value up to six further bytes in the range 0x80 to 0xbf.

You could even be more strict by checking for Unicode 3.1 conformance (i.e. a character has to be encoded in it's shortest form).

Look at utf8(7) for further details. (This manpage is included in the Debian manpages package.)

Best regards Uwe

-- 
Uwe Kleine-König

http://www.google.com/search?q=5+choose+3
Previous: Johannes SchindelinNext: Uwe Kleine-König
Message 17 of 39 in “Fix documentation copy&paste typo”
  1. Fix documentation copy&paste typoUwe Kleine-Koenig, Dec 8, 2006
  2. Uwe Kleine-KönigDec 19, 2006
  3. Junio C HamanoDec 19, 2006
  4. specify charset for commits (Was: [PATCH] Fix documentation copy&paste typo)Uwe Kleine-König, Dec 21, 2006
  5. Johannes SchindelinDec 21, 2006
  6. Santi BéjarDec 21, 2006
  7. Alexander LitvinovDec 21, 2006
  8. Jakub NarebskiDec 21, 2006
  9. Alexander LitvinovDec 21, 2006
  10. Jakub NarebskiDec 21, 2006
  11. Uwe Kleine-KönigDec 21, 2006
  12. Junio C HamanoDec 21, 2006
  13. Nicolas PitreDec 21, 2006
  14. Uwe Kleine-KönigDec 21, 2006
  15. Alexander LitvinovDec 21, 2006
  16. Johannes SchindelinDec 22, 2006
  17. Uwe Kleine-KönigDec 22, 2006
  18. Uwe Kleine-KönigDec 22, 2006
  19. Nicolas PitreDec 22, 2006
  20. Junio C HamanoDec 22, 2006
  21. 1/2 libgit.a: add some UTF-8 handling functionsJohannes Schindelin, Dec 22, 2006
  22. Junio C HamanoDec 22, 2006
  23. Johannes SchindelinDec 22, 2006
  24. Junio C HamanoDec 22, 2006
  25. Johannes SchindelinDec 22, 2006
  26. Junio C HamanoDec 22, 2006
  27. Alexander LitvinovDec 25, 2006
  28. Uwe Kleine-KönigDec 22, 2006
  29. Uwe Kleine-KönigDec 22, 2006
  30. Johannes SchindelinDec 22, 2006
  31. Johannes SchindelinDec 22, 2006
  32. Uwe Kleine-KönigDec 23, 2006
  33. Johannes SchindelinDec 23, 2006
  34. warn non utf-8 commit log messages.Junio C Hamano, Dec 23, 2006
  35. Johannes SchindelinDec 23, 2006
  36. 2/2 git-commit-tree: if i18n.commitencoding is utf-8 (default), check itJohannes Schindelin, Dec 22, 2006
  37. Junio C HamanoDec 22, 2006
  38. Johannes SchindelinDec 22, 2006
  39. 3/2 Wrap lines in shortlogJohannes Schindelin, Dec 22, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.