Commit 30752b74281f02ede8529bc005df67804f3772f5

Authored by Jürgen Knödlseder
1 parent c1e8a277

Add gammalib::number() function (#1743).

ChangeLog
1   -2016-03-06 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
  1 +2016-03-14 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
2 2  
3 3 * Version 1.1.0 released
4 4 =========================
5 5  
  6 + Add gammalib::number() function (#1743).
6 7 Add energy dispersion cube for stacked analysis (#1721).
7 8 Add GEnergy division operator.
8 9 Support Fermi LAT Pass 8 response functions (#1517)
... ...
... ... @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 1.1.0
2 2  
3 3 Author(s) : Juergen Knoedlseder
4 4  
5   -6 March 2016
  5 +14 March 2016
6 6  
7 7  
8 8 1. Introduction
... ... @@ -213,6 +213,9 @@ file name without the path.
213 213 Put FITS access in a critical OMP zone to make GFilename::is_fits() thread
214 214 safe (#1717).
215 215  
  216 +The gammalib::number() function was added to convert a singular noun into
  217 +a plural noun is the number of instances of the noun is not one (#1743).
  218 +
216 219  
217 220 14. XML module
218 221 --------------
... ...
include/GTools.hpp
... ... @@ -86,6 +86,7 @@ namespace gammalib {
86 86 std::string centre(const std::string& s, const int& n,
87 87 const char& c = ' ');
88 88 std::string parformat(const std::string& s, const int& indent = 0);
  89 + std::string number(const std::string& noun, const int& number);
89 90 double plaw_photon_flux(const double& emin,
90 91 const double& emax,
91 92 const double& epivot,
... ...
pyext/GTools.i
... ... @@ -53,6 +53,7 @@ namespace gammalib {
53 53 std::string right(const std::string& s, int n, char c = ' ');
54 54 std::string centre(const std::string& s, int n, char c = ' ');
55 55 std::string parformat(const std::string& s, const int& indent = 0);
  56 + std::string number(const std::string& noun, const int& number);
56 57 double plaw_photon_flux(const double& emin,
57 58 const double& emax,
58 59 const double& epivot,
... ...
src/support/GTools.cpp
1 1 /***************************************************************************
2 2 * GTools.cpp - GammaLib tools *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2008-2015 by Juergen Knoedlseder *
  4 + * copyright (C) 2008-2016 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -862,7 +862,7 @@ std::string gammalib::centre(const std::string&amp; s, const int&amp; n, const char&amp; c)
862 862 * @brief Convert string in parameter format
863 863 *
864 864 * @param[in] s String to be converted.
865   - * @param[in] indent Indentation of parameter (default: 0).
  865 + * @param[in] indent Indentation of parameter.
866 866 * @return Parameter string.
867 867 *
868 868 * Converts and string into the parameter format of type "s ......: " with a
... ... @@ -883,6 +883,31 @@ std::string gammalib::parformat(const std::string&amp; s, const int&amp; indent)
883 883  
884 884  
885 885 /***********************************************************************//**
  886 + * @brief Convert singular noun into number noun
  887 + *
  888 + * @param[in] noun Singular noun.
  889 + * @param[in] number Number of instance of noun.
  890 + * @return Converted noun.
  891 + *
  892 + * Converts a singular noun into a number noun by appending a "s" to the
  893 + * noun if the @p number of the instances of the noun is not one.
  894 + ***************************************************************************/
  895 +std::string gammalib::number(const std::string& noun, const int& number)
  896 +{
  897 + // Copy input noun
  898 + std::string result(noun);
  899 +
  900 + // Append "s" if number if not one
  901 + if (number != 1) {
  902 + result += "s";
  903 + }
  904 +
  905 + // Return result
  906 + return result;
  907 +}
  908 +
  909 +
  910 +/***********************************************************************//**
886 911 * @brief Compute photon flux between two energies for a power law
887 912 *
888 913 * @param[in] emin Minimum energy.
... ...
test/test_GSupport.cpp
... ... @@ -81,6 +81,27 @@ TestGSupport* TestGSupport::clone(void) const
81 81 ***************************************************************************/
82 82 void TestGSupport::test_tools(void)
83 83 {
  84 + // Strip whitespace
  85 + test_assert(gammalib::strip_whitespace(" World ") == "World",
  86 + "gammalib::strip_whitespace(\" World \")");
  87 + test_assert(gammalib::strip_whitespace("World ") == "World",
  88 + "gammalib::strip_whitespace(\"World \")");
  89 + test_assert(gammalib::strip_whitespace(" World") == "World",
  90 + "gammalib::strip_whitespace(\" World\")");
  91 +
  92 + // Strip characters
  93 + test_assert(gammalib::strip_chars("xxWorldyy", "xy") == "World",
  94 + "gammalib::strip_chars(\"xxWorldyy\")");
  95 + test_assert(gammalib::strip_chars("Worldxy", "xy") == "World",
  96 + "gammalib::strip_chars(\"Worldxy\")");
  97 + test_assert(gammalib::strip_chars("xxWorld", "x") == "World",
  98 + "gammalib::strip_chars(\"xxWorld\")");
  99 +
  100 + // Test noun number conversion
  101 + test_assert(gammalib::number("World", 0) == "Worlds", "Zero Worlds");
  102 + test_assert(gammalib::number("World", 1) == "World", "One World");
  103 + test_assert(gammalib::number("World", 2) == "Worlds", "Two Worlds");
  104 +
84 105 // Test XML to string conversion
85 106 std::string s_in = "Hallo World, you \"are\" my 'nice' <planet> & place";
86 107 std::string s_ref = "Hallo World, you &quot;are&quot; my &apos;nice&apos;"
... ...