Skip to content

Commit 128b07e

Browse files
authored
Issue 134, use std::unique_ptr in RuCommonConceptFactory.cpp (#135)
1 parent 90d4910 commit 128b07e

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

inflection/src/inflection/dialog/language/RuCommonConceptFactory.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ ::inflection::dialog::SpeakableString RuCommonConceptFactory::quantifyType(const
4747
type = ::inflection::grammar::synthesis::GrammemeConstants::NUMBER_SINGULAR();
4848
semanticConceptClone->putConstraint(semanticFeatureCase, ::inflection::grammar::synthesis::GrammemeConstants::CASE_GENITIVE());
4949
} else {
50-
auto caseSpeakableString = semanticConceptClone->getFeatureValue(semanticFeatureCase);
50+
std::unique_ptr<SpeakableString> caseSpeakableString(
51+
semanticConceptClone->getFeatureValue(semanticFeatureCase));
5152
::std::u16string caseString;
52-
if (caseSpeakableString != nullptr && ::inflection::grammar::synthesis::GrammemeConstants::CASE_NOMINATIVE() != npc(caseSpeakableString)->getPrint()) {
53-
caseString = npc(caseSpeakableString)->getPrint();
53+
if (caseSpeakableString != nullptr && ::inflection::grammar::synthesis::GrammemeConstants::CASE_NOMINATIVE() != caseSpeakableString->getPrint()) {
54+
caseString = caseSpeakableString->getPrint();
5455
}
55-
delete caseSpeakableString;
5656
if (caseString.empty() || ::inflection::grammar::synthesis::GrammemeConstants::CASE_NOMINATIVE() == caseString || ::inflection::grammar::synthesis::GrammemeConstants::CASE_ACCUSATIVE() == caseString) {
5757
semanticConceptClone->putConstraint(semanticFeatureCase, ::inflection::grammar::synthesis::GrammemeConstants::CASE_GENITIVE());
5858
}
@@ -62,13 +62,13 @@ ::inflection::dialog::SpeakableString RuCommonConceptFactory::quantifyType(const
6262
if (::inflection::grammar::synthesis::GrammemeConstants::CASE_ACCUSATIVE() == caseString && Plurality::Rule::FEW == countType) {
6363
::std::unique_ptr<SemanticFeatureConceptBase> semanticConceptCloneForAnimacy(npc(semanticConcept.clone()));
6464
semanticConceptCloneForAnimacy->clearConstraint(semanticFeatureCase);
65-
auto animacySpeakableString = semanticConceptCloneForAnimacy->getFeatureValue(semanticFeatureAnimacy);
66-
if (animacySpeakableString != nullptr && ::inflection::grammar::synthesis::GrammemeConstants::ANIMACY_INANIMATE() == npc(animacySpeakableString)->getPrint()) {
65+
std::unique_ptr<SpeakableString> animacySpeakableString(
66+
semanticConceptCloneForAnimacy->getFeatureValue(semanticFeatureAnimacy));
67+
if (animacySpeakableString != nullptr && ::inflection::grammar::synthesis::GrammemeConstants::ANIMACY_INANIMATE() == animacySpeakableString->getPrint()) {
6768
type = ::inflection::grammar::synthesis::GrammemeConstants::NUMBER_SINGULAR();
6869
} else {
6970
type = ::inflection::grammar::synthesis::GrammemeConstants::NUMBER_PLURAL();
7071
}
71-
delete animacySpeakableString;
7272
} else {
7373
type = ::inflection::grammar::synthesis::GrammemeConstants::NUMBER_PLURAL();
7474
}
@@ -85,18 +85,19 @@ ::inflection::dialog::SpeakableString RuCommonConceptFactory::quantifyType(const
8585

8686
inflection::dialog::SpeakableString* RuCommonConceptFactory::quantify(const NumberConcept& number, const SemanticFeatureConceptBase* semanticConcept) const
8787
{
88-
auto genderSpeakableString = npc(semanticConcept)->getFeatureValue(semanticFeatureGender);
88+
std::unique_ptr<SpeakableString> genderSpeakableString(
89+
npc(semanticConcept)->getFeatureValue(semanticFeatureGender));
8990
::std::u16string gender;
9091
if (genderSpeakableString != nullptr) {
91-
gender = npc(genderSpeakableString)->getPrint();
92-
delete genderSpeakableString;
92+
gender = genderSpeakableString->getPrint();
9393
}
9494
inflection::dialog::SpeakableString formattedNumber({});
9595
if (!gender.empty()) {
96-
auto caseSpeakableString = npc(semanticConcept)->getFeatureValue(semanticFeatureCase);
96+
std::unique_ptr<SpeakableString> caseSpeakableString(
97+
npc(semanticConcept)->getFeatureValue(semanticFeatureCase));
9798
::std::u16string caseString;
98-
if (caseSpeakableString != nullptr && ::inflection::grammar::synthesis::GrammemeConstants::CASE_NOMINATIVE() != npc(caseSpeakableString)->getPrint()) {
99-
caseString = npc(caseSpeakableString)->getPrint();
99+
if (caseSpeakableString != nullptr && ::inflection::grammar::synthesis::GrammemeConstants::CASE_NOMINATIVE() != caseSpeakableString->getPrint()) {
100+
caseString = caseSpeakableString->getPrint();
100101
// TODO Deprecated usage based on bad advice when Russian was first started. We can change this once RBNF is updated.
101102
if (caseString == ::inflection::grammar::synthesis::GrammemeConstants::CASE_INSTRUMENTAL()) {
102103
caseString = ::inflection::grammar::synthesis::GrammemeConstants::CASE_ABLATIVE();
@@ -106,7 +107,6 @@ inflection::dialog::SpeakableString* RuCommonConceptFactory::quantify(const Numb
106107
}
107108
caseString = ::std::u16string(u"-") + caseString;
108109
}
109-
delete caseSpeakableString;
110110
formattedNumber = number.asSpokenWords(::std::u16string(u"cardinal-") + gender + caseString);
111111
} else {
112112
// We don't know what this word is. Default to digits.

0 commit comments

Comments
 (0)