aboutsummaryrefslogtreecommitdiffstats
path: root/src/fns.c
diff options
context:
space:
mode:
authorMichael Albinus2014-08-29 19:57:36 +0200
committerMichael Albinus2014-08-29 19:57:36 +0200
commitb579ae53e46fa9bc9a242e4d5ce524097b3150ef (patch)
treece4ad68e2d233733560ee794ba94cd4c79691f78 /src/fns.c
parent55412cd901f4f3c507c9626061acae7e9ced6785 (diff)
downloademacs-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.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/src/fns.c b/src/fns.c
index 2b1fb86419d..3cca40df50f 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -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
347DEFUN ("string-collate-lessp", Fstring_collate_lessp, Sstring_collate_lessp, 2, 2, 0, 347DEFUN ("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 349Symbols are also allowed; their print names are used instead.
350Case is significant. Symbols are also allowed; their print names are
351used instead.
352 350
353This function obeys the conventions for collation order in your 351This function obeys the conventions for collation order in your
354locale settings. For example, punctuation and whitespace characters 352locale settings. For example, punctuation and whitespace characters
355are considered less significant for sorting. 353are 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
360If your system does not support a locale environment, this function 358The optional argument LOCALE, a string, overrides the setting of your
361behaves like `string-lessp'. 359current locale identifier for collation. The value is system
360dependent; a LOCALE \"en_US.UTF-8\" is applicable on POSIX systems,
361while it would be \"English_USA.1252\" on MS Windows systems.
362 362
363If the environment variable \"LC_COLLATE\" is set in `process-environment', 363If IGNORE-CASE is non-nil, characters are converted to lower-case
364it overrides the setting of your current locale. */) 364before comparing them.
365 (Lisp_Object s1, Lisp_Object s2) 365
366If your system does not support a locale environment, this function
367behaves 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
383DEFUN ("string-collate-equalp", Fstring_collate_equalp, Sstring_collate_equalp, 2, 2, 0, 388DEFUN ("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 390Symbols are also allowed; their print names are used instead.
386Case is significant. Symbols are also allowed; their print names are
387used instead.
388 391
389This function obeys the conventions for collation order in your locale 392This function obeys the conventions for collation order in your locale
390settings. For example, characters with different coding points but 393settings. For example, characters with different coding points but
391the same meaning are considered as equal, like different grave accent 394the same meaning are considered as equal, like different grave accent
392unicode characters. 395unicode 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
397If your system does not support a locale environment, this function 400The optional argument LOCALE, a string, overrides the setting of your
398behaves like `string-equal'. 401current locale identifier for collation. The value is system
402dependent; a LOCALE \"en_US.UTF-8\" is applicable on POSIX systems,
403while it would be \"English_USA.1252\" on MS Windows systems.
399 404
400If the environment variable \"LC_COLLATE\" is set in `process-environment', 405If IGNORE-CASE is non-nil, characters are converted to lower-case
401it overrides the setting of your current locale. */) 406before comparing them.
402 (Lisp_Object s1, Lisp_Object s2) 407
408If your system does not support a locale environment, this function
409behaves 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);