| 1 | // Aseprite Code Generator |
| 2 | // Copyright (C) 2014-2015 David Capello |
| 3 | // |
| 4 | // This file is released under the terms of the MIT license. |
| 5 | // Read LICENSE.txt for more information. |
| 6 | |
| 7 | #ifndef GEN_COMMON_H_INCLUDED |
| 8 | #define GEN_COMMON_H_INCLUDED |
| 9 | #pragma once |
| 10 | |
| 11 | #include <cctype> |
| 12 | #include <string> |
| 13 | |
| 14 | inline std::string convert_xmlid_to_cppid(const std::string& xmlid, bool firstLetterUpperCase) |
| 15 | { |
| 16 | bool firstLetter = firstLetterUpperCase; |
| 17 | std::string cppid; |
| 18 | for (std::size_t i=0; i<xmlid.size(); ++i) { |
| 19 | if (xmlid[i] == '_') { |
| 20 | firstLetter = true; |
| 21 | } |
| 22 | else if (firstLetter) { |
| 23 | firstLetter = false; |
| 24 | cppid += std::toupper(xmlid[i]); |
| 25 | } |
| 26 | else |
| 27 | cppid += xmlid[i]; |
| 28 | } |
| 29 | return cppid; |
| 30 | } |
| 31 | |
| 32 | #endif |
| 33 | |