diff options
| author | Michael Albinus | 2014-08-29 19:57:36 +0200 |
|---|---|---|
| committer | Michael Albinus | 2014-08-29 19:57:36 +0200 |
| commit | b579ae53e46fa9bc9a242e4d5ce524097b3150ef (patch) | |
| tree | ce4ad68e2d233733560ee794ba94cd4c79691f78 /src/fns.c | |
| parent | 55412cd901f4f3c507c9626061acae7e9ced6785 (diff) | |
| download | emacs-b579ae53e46fa9bc9a242e4d5ce524097b3150ef.tar.gz emacs-b579ae53e46fa9bc9a242e4d5ce524097b3150ef.zip | |
Add optional arguments LOCALE and IGNORE-CASE to collation functions.
* fns.c (Fstring_collate_lessp, Fstring_collate_equalp):
Add optional arguments LOCALE and IGNORE-CASE.
* lisp.h (str_collate): Adapt argument list.
* sysdep.c (LC_CTYPE, LC_CTYPE_MASK, towlower_l):
Define substitutes for platforms that lack them.
(str_collate): Add arguments locale and ignore_case.
Diffstat (limited to 'src/fns.c')
| -rw-r--r-- | src/fns.c | 54 |
1 files changed, 32 insertions, 22 deletions
| @@ -344,25 +344,28 @@ Symbols are also allowed; their print names are used instead. */) | |||
| 344 | return i1 < SCHARS (s2) ? Qt : Qnil; | 344 | return i1 < SCHARS (s2) ? Qt : Qnil; |
| 345 | } | 345 | } |
| 346 | 346 | ||
| 347 | DEFUN ("string-collate-lessp", Fstring_collate_lessp, Sstring_collate_lessp, 2, 2, 0, | 347 | DEFUN ("string-collate-lessp", Fstring_collate_lessp, Sstring_collate_lessp, 2, 4, 0, |
| 348 | doc: /* Return t if first arg string is less than second in collation order. | 348 | doc: /* Return t if first arg string is less than second in collation order. |
| 349 | 349 | Symbols are also allowed; their print names are used instead. | |
| 350 | Case is significant. Symbols are also allowed; their print names are | ||
| 351 | used instead. | ||
| 352 | 350 | ||
| 353 | This function obeys the conventions for collation order in your | 351 | This function obeys the conventions for collation order in your |
| 354 | locale settings. For example, punctuation and whitespace characters | 352 | locale settings. For example, punctuation and whitespace characters |
| 355 | are considered less significant for sorting. | 353 | are considered less significant for sorting: |
| 356 | 354 | ||
| 357 | \(sort '\("11" "12" "1 1" "1 2" "1.1" "1.2") 'string-collate-lessp) | 355 | \(sort '\("11" "12" "1 1" "1 2" "1.1" "1.2") 'string-collate-lessp) |
| 358 | => \("11" "1 1" "1.1" "12" "1 2" "1.2") | 356 | => \("11" "1 1" "1.1" "12" "1 2" "1.2") |
| 359 | 357 | ||
| 360 | If your system does not support a locale environment, this function | 358 | The optional argument LOCALE, a string, overrides the setting of your |
| 361 | behaves like `string-lessp'. | 359 | current locale identifier for collation. The value is system |
| 360 | dependent; a LOCALE \"en_US.UTF-8\" is applicable on POSIX systems, | ||
| 361 | while it would be \"English_USA.1252\" on MS Windows systems. | ||
| 362 | 362 | ||
| 363 | If the environment variable \"LC_COLLATE\" is set in `process-environment', | 363 | If IGNORE-CASE is non-nil, characters are converted to lower-case |
| 364 | it overrides the setting of your current locale. */) | 364 | before comparing them. |
| 365 | (Lisp_Object s1, Lisp_Object s2) | 365 | |
| 366 | If your system does not support a locale environment, this function | ||
| 367 | behaves like `string-lessp'. */) | ||
| 368 | (Lisp_Object s1, Lisp_Object s2, Lisp_Object locale, Lisp_Object ignore_case) | ||
| 366 | { | 369 | { |
| 367 | #if defined __STDC_ISO_10646__ || defined WINDOWSNT | 370 | #if defined __STDC_ISO_10646__ || defined WINDOWSNT |
| 368 | /* Check parameters. */ | 371 | /* Check parameters. */ |
| @@ -372,34 +375,39 @@ it overrides the setting of your current locale. */) | |||
| 372 | s2 = SYMBOL_NAME (s2); | 375 | s2 = SYMBOL_NAME (s2); |
| 373 | CHECK_STRING (s1); | 376 | CHECK_STRING (s1); |
| 374 | CHECK_STRING (s2); | 377 | CHECK_STRING (s2); |
| 378 | if (!NILP (locale)) | ||
| 379 | CHECK_STRING (locale); | ||
| 375 | 380 | ||
| 376 | return (str_collate (s1, s2) < 0) ? Qt : Qnil; | 381 | return (str_collate (s1, s2, locale, ignore_case) < 0) ? Qt : Qnil; |
| 377 | 382 | ||
| 378 | #else /* !__STDC_ISO_10646__, !WINDOWSNT */ | 383 | #else /* !__STDC_ISO_10646__, !WINDOWSNT */ |
| 379 | return Fstring_lessp (s1, s2); | 384 | return Fstring_lessp (s1, s2); |
| 380 | #endif /* !__STDC_ISO_10646__, !WINDOWSNT */ | 385 | #endif /* !__STDC_ISO_10646__, !WINDOWSNT */ |
| 381 | } | 386 | } |
| 382 | 387 | ||
| 383 | DEFUN ("string-collate-equalp", Fstring_collate_equalp, Sstring_collate_equalp, 2, 2, 0, | 388 | DEFUN ("string-collate-equalp", Fstring_collate_equalp, Sstring_collate_equalp, 2, 4, 0, |
| 384 | doc: /* Return t if two strings have identical contents. | 389 | doc: /* Return t if two strings have identical contents. |
| 385 | 390 | Symbols are also allowed; their print names are used instead. | |
| 386 | Case is significant. Symbols are also allowed; their print names are | ||
| 387 | used instead. | ||
| 388 | 391 | ||
| 389 | This function obeys the conventions for collation order in your locale | 392 | This function obeys the conventions for collation order in your locale |
| 390 | settings. For example, characters with different coding points but | 393 | settings. For example, characters with different coding points but |
| 391 | the same meaning are considered as equal, like different grave accent | 394 | the same meaning are considered as equal, like different grave accent |
| 392 | unicode characters. | 395 | unicode characters: |
| 393 | 396 | ||
| 394 | \(string-collate-equalp \(string ?\\uFF40) \(string ?\\u1FEF)) | 397 | \(string-collate-equalp \(string ?\\uFF40) \(string ?\\u1FEF)) |
| 395 | => t | 398 | => t |
| 396 | 399 | ||
| 397 | If your system does not support a locale environment, this function | 400 | The optional argument LOCALE, a string, overrides the setting of your |
| 398 | behaves like `string-equal'. | 401 | current locale identifier for collation. The value is system |
| 402 | dependent; a LOCALE \"en_US.UTF-8\" is applicable on POSIX systems, | ||
| 403 | while it would be \"English_USA.1252\" on MS Windows systems. | ||
| 399 | 404 | ||
| 400 | If the environment variable \"LC_COLLATE\" is set in `process-environment', | 405 | If IGNORE-CASE is non-nil, characters are converted to lower-case |
| 401 | it overrides the setting of your current locale. */) | 406 | before comparing them. |
| 402 | (Lisp_Object s1, Lisp_Object s2) | 407 | |
| 408 | If your system does not support a locale environment, this function | ||
| 409 | behaves like `string-equal'. */) | ||
| 410 | (Lisp_Object s1, Lisp_Object s2, Lisp_Object locale, Lisp_Object ignore_case) | ||
| 403 | { | 411 | { |
| 404 | #if defined __STDC_ISO_10646__ || defined WINDOWSNT | 412 | #if defined __STDC_ISO_10646__ || defined WINDOWSNT |
| 405 | /* Check parameters. */ | 413 | /* Check parameters. */ |
| @@ -409,8 +417,10 @@ it overrides the setting of your current locale. */) | |||
| 409 | s2 = SYMBOL_NAME (s2); | 417 | s2 = SYMBOL_NAME (s2); |
| 410 | CHECK_STRING (s1); | 418 | CHECK_STRING (s1); |
| 411 | CHECK_STRING (s2); | 419 | CHECK_STRING (s2); |
| 420 | if (!NILP (locale)) | ||
| 421 | CHECK_STRING (locale); | ||
| 412 | 422 | ||
| 413 | return (str_collate (s1, s2) == 0) ? Qt : Qnil; | 423 | return (str_collate (s1, s2, locale, ignore_case) == 0) ? Qt : Qnil; |
| 414 | 424 | ||
| 415 | #else /* !__STDC_ISO_10646__, !WINDOWSNT */ | 425 | #else /* !__STDC_ISO_10646__, !WINDOWSNT */ |
| 416 | return Fstring_equal (s1, s2); | 426 | return Fstring_equal (s1, s2); |