Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "Declaration.h" |
| 18 | |
Steven Moreland | 95b4623 | 2016-09-20 14:46:55 -0700 | [diff] [blame^] | 19 | #include <hidl-util/StringHelper.h> |
Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 20 | #include <regex> |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | static const std::regex RE_LEADING_SPACES("\n +"); |
| 25 | |
| 26 | Declaration::Declaration(const std::string &name) |
| 27 | : mName(name) |
| 28 | {} |
| 29 | |
| 30 | Declaration::~Declaration() {} |
| 31 | |
| 32 | const std::string& Declaration::getName() const { |
| 33 | return mName; |
| 34 | } |
| 35 | void Declaration::setName(const std::string &name) { |
| 36 | mName = name; |
| 37 | } |
| 38 | |
Steven Moreland | 95b4623 | 2016-09-20 14:46:55 -0700 | [diff] [blame^] | 39 | void Declaration::forceCamelCase() { |
| 40 | mName = StringHelper::RTrim(mName, "_t"); |
| 41 | mName = StringHelper::SnakeCaseToCamelCase(mName); |
| 42 | } |
| 43 | |
| 44 | void Declaration::forcePascalCase() { |
| 45 | mName = StringHelper::RTrim(mName, "_t"); |
| 46 | mName = StringHelper::SnakeCaseToPascalCase(mName); |
| 47 | } |
| 48 | |
Steven Moreland | f1a35f7 | 2016-08-17 08:41:49 -0700 | [diff] [blame] | 49 | const std::string& Declaration::getComment() const { |
| 50 | return mComment; |
| 51 | } |
| 52 | void Declaration::setComment(const std::string &comment) { |
| 53 | // remove excess leading whitespace |
| 54 | mComment = regex_replace(comment, RE_LEADING_SPACES, "\n "); |
| 55 | } |
| 56 | |
| 57 | void Declaration::generateCommentText(Formatter &out) const { |
| 58 | if (!mComment.empty()) { |
| 59 | out << mComment << "\n"; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | void Declaration::generateParameterSource(Formatter &out) const { |
| 64 | out << "/* UNKOWN PARAMTER */" << "\n"; |
| 65 | } |
| 66 | |
| 67 | } //namespace android |