Scid  4.6.5
string.tcl
Go to the documentation of this file.
1 
2 # ::utils::string::Surname
3 #
4 # Returns the surname of a player name.
5 #
6 proc ::utils::string::Surname {name} {
7  set idx [string first "," $name]
8  if {$idx > 0} { set name [string range $name 0 [expr {$idx - 1}]]}
9  return $name
10 }
11 
12 
13 proc ::utils::string::CityName {siteName} {
14  regsub { [A-Z][A-Z][A-Z]$} $siteName "" siteName
15  return [string trim [::utils::string::Surname $siteName]]
16 }
17 
18 
19 # ::utils::string::Capital
20 #
21 # Returns a string with the first character capitalised.
22 #
23 proc ::utils::string::Capital {str} {
24  set s [string toupper [string index $str 0]]
25  append s [string range $str 1 end]
26  return $s
27 }
28 
29 # PadLeft
30 #
31 # Given a string and a length, pads the string with padChar to have
32 # the required length.
33 #
34 proc ::utils::string::PadLeft {str length {padChar " "}} {
35  set s $str
36  for {set actual [string length $s]} {$actual < $length} {incr actual} {
37  append s $padChar
38  }
39  return $s
40 }
41 
42 # Pad
43 #
44 # Same as PadLeft.
45 #
46 proc ::utils::string::Pad {str length {padChar " "}} {
47  return [::utils::string::PadLeft $str $length $padChar]
48 }
49 
50 # PadRight
51 #
52 # Like PadLeft, but adds the padding characters to the start of the string.
53 #
54 proc ::utils::string::PadRight {str length {padChar " "}} {
55  set s $str
56  for {set actual [string length $s]} {$actual < $length} {incr actual} {
57  set s "$padChar$s"
58  }
59  return $s
60 }
61 
62 # PadCenter
63 #
64 # Like PadLeft and PadRight, but centers the specified string.
65 #
66 proc ::utils::string::PadCenter {str length {padChar " "}} {
67  set pre 1
68  set s $str
69  for {set actual [string length $s]} {$actual < $length} {incr actual} {
70  if {$pre} {
71  set s "$padChar$s"
72  set pre 0
73  } else {
74  append s $padChar
75  set pre 1
76  }
77  }
78  return $s
79 }
80