This repository was archived by the owner on Jan 27, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathUtils.h
More file actions
69 lines (59 loc) · 2.33 KB
/
Copy pathUtils.h
File metadata and controls
69 lines (59 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//=================================================================================================
// Author: Jerome Richards
// Assignment: Program 7 Graphs
// File: Utils.h
// Instructor: Dr. Reza Sanati
// Class: CS 2420-002
// Date Written: 08-December-2015
//
// Description
//
// Contains utility functions that may be used broadly across the software
//=================================================================================================
#pragma once
#include <string>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <locale>
class Utils
{
public:
//-------------------------------------------------------------------------------------------------
// Function Name: toLower
// Purpose: converts input to lower case and returns the result as a new string
//
// Parameters: string reference (theSting) holds the string to be converted to lowercase
// Returns: string result contains the converted string
// Pre-conditions: none
// Post-conditions: none
//-------------------------------------------------------------------------------------------------
static std::string toLower(const std::string& theString)
{
std::string result = theString;
std::transform(result.begin(), result.end(), result.begin(), ::tolower);
return result;
}
//-------------------------------------------------------------------------------------------------
// Function Name: toCurrency
// Purpose: converts input to the currency representation for the locale
//
// Parameters: double value
// bool removeDecimals
//
// Returns: string result contains the converted string
// Pre-conditions: none
// Post-conditions: none
//-------------------------------------------------------------------------------------------------
static std::string toCurrency(double value, bool removeDecimals = true)
{
std::stringstream ss;
ss.imbue(std::locale(""));
ss << std::showbase << std::put_money(value*100.0);
std::string result;
ss >> result;
if(removeDecimals)
result = result.substr(0, result.size() - 3);
return result;
}
};