Changeset 108 for trunk/UContact.pas
- Timestamp:
- Feb 11, 2022, 11:31:42 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UContact.pas
r104 r108 141 141 function GetProperty(Field: TContactField): TContactProperty; overload; 142 142 function GetProperty(FieldIndex: TContactFieldIndex): TContactProperty; overload; 143 procedure FullNameToNameParts(FullName: string; out Before, First, Middle, 144 Last, After: string); 145 function NamePartsToFullName(Before, First, Middle, Last, After: string): string; 143 146 procedure Assign(Source: TContact); 144 147 function UpdateFrom(Source: TContact): Boolean; … … 1116 1119 end; 1117 1120 1121 function IsNumber(Text: string): Boolean; 1122 var 1123 Value: Integer; 1124 begin 1125 Result := TryStrToInt(Text, Value); 1126 end; 1127 1128 function IsRomanNumber(Text: string): Boolean; 1129 var 1130 I: Integer; 1131 begin 1132 Result := True; 1133 for I := 1 to Length(Text) do 1134 if not (Text[I] in ['I', 'V', 'X', 'L', 'C', 'D', 'M']) then begin 1135 Result := False; 1136 Break; 1137 end; 1138 end; 1139 1140 procedure TContact.FullNameToNameParts(FullName: string; out Before, First, 1141 Middle, Last, After: string); 1142 var 1143 Parts: TStringArray; 1144 I, J: Integer; 1145 begin 1146 Before := ''; 1147 First := ''; 1148 Middle := ''; 1149 Last := ''; 1150 After := ''; 1151 while Pos(' ', FullName) > 0 do 1152 FullName := StringReplace(FullName, ' ', ' ', [rfReplaceAll]); 1153 Parts := Explode(' ', Trim(FullName)); 1154 1155 // Title before 1156 while (Length(Parts) > 0) and EndsWith(Parts[0], '.') do begin 1157 Before := Trim(Before + ' ' + Parts[0]); 1158 Delete(Parts, 0, 1); 1159 end; 1160 1161 // Title after 1162 for I := 0 to High(Parts) do 1163 if (Pos('.', Parts[I]) > 0) or IsNumber(Parts[I]) or IsRomanNumber(Parts[I]) then begin 1164 for J := I to High(Parts) do 1165 After := Trim(After + ' ' + Parts[J]); 1166 SetLength(Parts, I); 1167 Break; 1168 end; 1169 1170 if Length(Parts) = 0 then begin 1171 end else 1172 if Length(Parts) = 1 then begin 1173 First := Parts[0]; 1174 end else 1175 if Length(Parts) = 2 then begin 1176 First := Parts[0]; 1177 Last := Parts[1]; 1178 end else begin 1179 First := Parts[0]; 1180 for I := 0 to Length(Parts) - 3 do 1181 Middle := Trim(Middle + ' ' + Parts[I + 1]); 1182 Last := Parts[High(Parts)]; 1183 end; 1184 end; 1185 1186 function TContact.NamePartsToFullName(Before, First, Middle, Last, After: string 1187 ): string; 1188 begin 1189 Result := ''; 1190 if Before <> '' then Result := Result + ' ' + Before; 1191 if First <> '' then Result := Result + ' ' + First; 1192 if Middle <> '' then Result := Result + ' ' + Middle; 1193 if Last <> '' then Result := Result + ' ' + Last; 1194 if After <> '' then Result := Result + ' ' + After; 1195 Result := Trim(Result); 1196 end; 1197 1118 1198 procedure TContact.Assign(Source: TContact); 1119 1199 begin
Note:
See TracChangeset
for help on using the changeset viewer.