source: trunk/m4/yat_string.m4 @ 4102

Last change on this file since 4102 was 4102, checked in by Peter, 2 years ago

add wrapper function that calls std::string::contains, ::starts_with, and ::ends_with, if available; otherwise use home-brewed code. Add autoconf tests that check if these functions are available in CXX.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Date
File size: 2.9 KB
Line 
1## $Id: yat_string.m4 4102 2021-09-22 07:50:18Z peter $
2#
3# Copyright (C) 2021 Peter Johansson
4#
5# This file is part of the yat library, https://dev.thep.lu.se/yat
6#
7# The yat library is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 3 of the
10# License, or (at your option) any later version.
11#
12# The yat library is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15# General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with yat. If not, see <https://www.gnu.org/licenses/>.
19#
20
21#
22# serial 1 (yat 0.20)
23#
24
25
26# YAT_FUNC_STRING_CONTAINS([action-if-found], [action-if-not-found]
27# =================================================================
28# Test if CXX supports std::string::contains. If not successful issue
29# action-if-not-found. If successful issue action-if-found, or if
30# empty issue AC_DEFINE([YAT_HAVE_FUNC_STRING_CONTAINS])
31AC_DEFUN([YAT_FUNC_STRING_CONTAINS],
32[
33  YAT_FUNC_STRING([contains], [$1], [$2])
34])
35
36
37# YAT_FUNC_STRING_ENDS_WITH([action-if-found], [action-if-not-found]
38# =================================================================
39# Test if CXX supports std::string::ends_with. If not successful issue
40# action-if-not-found. If successful issue action-if-found, or if
41# empty issue AC_DEFINE([YAT_HAVE_FUNC_STRING_ENDS_WITH])
42AC_DEFUN([YAT_FUNC_STRING_ENDS_WITH],
43[
44  YAT_FUNC_STRING([ends_with], [$1], [$2])
45])
46
47
48# YAT_FUNC_STRING_STARTS_WITH([action-if-found], [action-if-not-found]
49# =================================================================
50# Test if CXX supports std::string::starts_with. If not successful
51# issue action-if-not-found. If successful issue action-if-found, or
52# if empty issue AC_DEFINE([YAT_HAVE_FUNC_STRING_STARTS_WITH])
53AC_DEFUN([YAT_FUNC_STRING_STARTS_WITH],
54[
55  YAT_FUNC_STRING([starts_with], [$1], [$2])
56])
57
58
59# YAT_FUNC_STRING(funcion, [action-if-found], [action-if-not-found])
60# =================================================================
61# Test if CXX supports std::string::func-name. The test includes a
62# test for std::string::<function>(std::string),
63# std::string::<function>(char), and std::string::<function>(const
64# char*) If not successful issue action-if-not-found. If successful
65# issue action-if-found, or if empty issue
66# AC_DEFINE([YAT_HAVE_FUNC_STRING_<function>])
67AC_DEFUN([YAT_FUNC_STRING],
68[
69  YAT_CHECK_FUNC([string::$1], [
70    @%:@include <string>
71    ], [
72      std::string str("Hello world!");
73      str.$1("world");
74      str.$1('H');
75      str.$1(str);
76    ], [m4_default([$2],
77                   [AC_DEFINE(AS_TR_CPP([YAT_HAVE_FUNC_STRING_$1]), [1],
78                              [Define if you have function std::string::$1])
79                   ])
80    ], [$3]
81  )
82])
Note: See TracBrowser for help on using the repository browser.