Merge pull request #2849 from ozra/feature-2811-hump-snake-dash
Feature #2811 hump, snake and now dash
This commit is contained in:
commit
8264c3cbee
4 changed files with 57 additions and 12 deletions
23
lib/pure/etcpriv.nim
Normal file
23
lib/pure/etcpriv.nim
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
#
|
||||
# Nim's Runtime Library
|
||||
# (c) Copyright 2015 Nim Authors
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
## This module contains utils that are less then easy to categorize and
|
||||
## don't really warrant a specific module. They are private to compiler
|
||||
## and stdlib usage, and should not be used outside of that - they may
|
||||
## change or disappear at any time.
|
||||
|
||||
|
||||
# Used by pure/hashes.nim, and the compiler parsing
|
||||
const magicIdentSeparatorRuneByteWidth* = 3
|
||||
|
||||
# Used by pure/hashes.nim, and the compiler parsing
|
||||
proc isMagicIdentSeparatorRune*(cs: cstring, i: int): bool {. inline } =
|
||||
result = cs[i] == '\226' and
|
||||
cs[i + 1] == '\128' and
|
||||
cs[i + 2] == '\147' # en-dash # 145 = nb-hyphen
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
## result = !$h
|
||||
|
||||
import
|
||||
strutils
|
||||
strutils, etcpriv
|
||||
|
||||
type
|
||||
THash* = int ## a hash value; hash tables using these values should
|
||||
|
|
@ -124,13 +124,20 @@ proc hash*(x: string): THash =
|
|||
proc hashIgnoreStyle*(x: string): THash =
|
||||
## efficient hashing of strings; style is ignored
|
||||
var h: THash = 0
|
||||
for i in 0..x.len-1:
|
||||
var i = 0
|
||||
let xLen = x.len
|
||||
while i < xLen:
|
||||
var c = x[i]
|
||||
if c == '_':
|
||||
continue # skip _
|
||||
if c in {'A'..'Z'}:
|
||||
c = chr(ord(c) + (ord('a') - ord('A'))) # toLower()
|
||||
h = h !& ord(c)
|
||||
inc(i)
|
||||
elif isMagicIdentSeparatorRune(cstring(x), i):
|
||||
inc(i, magicIdentSeparatorRuneByteWidth)
|
||||
else:
|
||||
if c in {'A'..'Z'}:
|
||||
c = chr(ord(c) + (ord('a') - ord('A'))) # toLower()
|
||||
h = h !& ord(c)
|
||||
inc(i)
|
||||
|
||||
result = !$h
|
||||
|
||||
proc hashIgnoreCase*(x: string): THash =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue