Home | History | Annotate | Download | only in util
      1 // Copyright (c) 2017 Google Inc.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 #include <algorithm>
     16 #include <cstdint>
     17 #include <type_traits>
     18 
     19 #include "util/string_utils.h"
     20 
     21 namespace spvutils {
     22 
     23 std::string CardinalToOrdinal(size_t cardinal) {
     24   const size_t mod10 = cardinal % 10;
     25   const size_t mod100 = cardinal % 100;
     26   std::string suffix;
     27   if (mod10 == 1 && mod100 != 11)
     28     suffix = "st";
     29   else if (mod10 == 2 && mod100 != 12)
     30     suffix = "nd";
     31   else if (mod10 == 3 && mod100 != 13)
     32     suffix = "rd";
     33   else
     34     suffix = "th";
     35 
     36   return ToString(cardinal) + suffix;
     37 }
     38 
     39 }  // namespace spvutils
     40