summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/collation/collator_factory_icu.cpp
blob: b2d90d1b3d066c3619bfc2e1d8d9cb0736cae3f3 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/**
 *    Copyright (C) 2018-present MongoDB, Inc.
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the Server Side Public License, version 1,
 *    as published by MongoDB, Inc.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    Server Side Public License for more details.
 *
 *    You should have received a copy of the Server Side Public License
 *    along with this program. If not, see
 *    <http://www.mongodb.com/licensing/server-side-public-license>.
 *
 *    As a special exception, the copyright holders give permission to link the
 *    code of portions of this program with the OpenSSL library under certain
 *    conditions as described in each individual source file and distribute
 *    linked combinations including the program with the OpenSSL library. You
 *    must comply with the Server Side Public License in all respects for
 *    all of the code used other than as permitted herein. If you modify file(s)
 *    with this exception, you may extend this exception to your version of the
 *    file(s), but you are not obligated to do so. If you do not wish to do so,
 *    delete this exception statement from your version. If you delete this
 *    exception statement from all source files in the program, then also delete
 *    it in the license file.
 */

#include "mongo/platform/basic.h"

#include "mongo/db/query/collation/collator_factory_icu.h"

#include <memory>

#include <unicode/coll.h>
#include <unicode/errorcode.h>
#include <unicode/ucol.h>
#include <unicode/uvernum.h>

#include "mongo/bson/bsonobj.h"
#include "mongo/bson/util/bson_extract.h"
#include "mongo/db/query/collation/collator_interface_icu.h"
#include "mongo/util/str.h"

namespace mongo {

namespace {

constexpr StringData kFallbackLocaleName = "root"_sd;

// Helper methods for converting between ICU attributes and types used by Collation.

UColAttributeValue boolToAttribute(bool value) {
    if (value) {
        return UCOL_ON;
    }
    return UCOL_OFF;
}

bool attributeToBool(UColAttributeValue attribute) {
    switch (attribute) {
        case UCOL_ON:
            return true;
        case UCOL_OFF:
            return false;
        default:
            MONGO_UNREACHABLE;
    }
}

UColAttributeValue getCaseFirstAttribute(CollationCaseFirstEnum caseFirst) {
    switch (caseFirst) {
        case CollationCaseFirstEnum::kUpper:
            return UCOL_UPPER_FIRST;
        case CollationCaseFirstEnum::kLower:
            return UCOL_LOWER_FIRST;
        case CollationCaseFirstEnum::kOff:
            return UCOL_OFF;
        default:
            MONGO_UNREACHABLE;
    }

    MONGO_UNREACHABLE;
}

CollationCaseFirstEnum getCaseFirstFromAttribute(UColAttributeValue caseFirstAttribute) {
    switch (caseFirstAttribute) {
        case UCOL_UPPER_FIRST:
            return CollationCaseFirstEnum::kUpper;
        case UCOL_LOWER_FIRST:
            return CollationCaseFirstEnum::kLower;
        case UCOL_OFF:
            return CollationCaseFirstEnum::kOff;
        default:
            MONGO_UNREACHABLE;
    }
}

UColAttributeValue getStrengthAttribute(int strength) {
    switch (static_cast<CollationStrength>(strength)) {
        case CollationStrength::kPrimary:
            return UCOL_PRIMARY;
        case CollationStrength::kSecondary:
            return UCOL_SECONDARY;
        case CollationStrength::kTertiary:
            return UCOL_TERTIARY;
        case CollationStrength::kQuaternary:
            return UCOL_QUATERNARY;
        case CollationStrength::kIdentical:
            return UCOL_IDENTICAL;
        default:
            MONGO_UNREACHABLE;
    }

    MONGO_UNREACHABLE;
}

int getStrengthFromAttribute(UColAttributeValue strengthAttribute) {
    switch (strengthAttribute) {
        case UCOL_PRIMARY:
            return static_cast<int>(CollationStrength::kPrimary);
        case UCOL_SECONDARY:
            return static_cast<int>(CollationStrength::kSecondary);
        case UCOL_TERTIARY:
            return static_cast<int>(CollationStrength::kTertiary);
        case UCOL_QUATERNARY:
            return static_cast<int>(CollationStrength::kQuaternary);
        case UCOL_IDENTICAL:
            return static_cast<int>(CollationStrength::kIdentical);
        default:
            MONGO_UNREACHABLE;
    }
}

UColAttributeValue getAlternateAttribute(CollationAlternateEnum alternate) {
    switch (alternate) {
        case CollationAlternateEnum::kNonIgnorable:
            return UCOL_NON_IGNORABLE;
        case CollationAlternateEnum::kShifted:
            return UCOL_SHIFTED;
        default:
            MONGO_UNREACHABLE;
    }

    MONGO_UNREACHABLE;
}

CollationAlternateEnum getAlternateFromAttribute(UColAttributeValue alternateAttribute) {
    switch (alternateAttribute) {
        case UCOL_NON_IGNORABLE:
            return CollationAlternateEnum::kNonIgnorable;
        case UCOL_SHIFTED:
            return CollationAlternateEnum::kShifted;
        default:
            MONGO_UNREACHABLE;
    }
}

UColReorderCode getMaxVariableReorderCode(CollationMaxVariableEnum maxVariable) {
    switch (maxVariable) {
        case CollationMaxVariableEnum::kPunct:
            return UCOL_REORDER_CODE_PUNCTUATION;
        case CollationMaxVariableEnum::kSpace:
            return UCOL_REORDER_CODE_SPACE;
        default:
            MONGO_UNREACHABLE;
    }

    MONGO_UNREACHABLE;
}

CollationMaxVariableEnum getMaxVariableFromReorderCode(UColReorderCode maxVariableReorderCode) {
    switch (maxVariableReorderCode) {
        case UCOL_REORDER_CODE_PUNCTUATION:
            return CollationMaxVariableEnum::kPunct;
        case UCOL_REORDER_CODE_SPACE:
            return CollationMaxVariableEnum::kSpace;
        default:
            MONGO_UNREACHABLE;
    }
}

// Sets the Collation's localeID to 'localeID'. For each collation option, if the user specified the
// option then set it on icuCollation, otherwise copy icuCollation's default to the Collation.
Status updateCollationSpecFromICUCollator(const BSONObj& spec,
                                          const std::string& localeID,
                                          icu::Collator* icuCollator,
                                          Collation* collation) {
    // Set the localeID.
    collation->setLocale(localeID);

    // Set caseLevel.
    if (!spec.hasField(Collation::kCaseLevelFieldName)) {
        UErrorCode status = U_ZERO_ERROR;
        UColAttributeValue caseLevelAttribute = icuCollator->getAttribute(UCOL_CASE_LEVEL, status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to get '" << Collation::kCaseLevelFieldName
                                  << "' attribute from icu::Collator: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
        collation->setCaseLevel(attributeToBool(caseLevelAttribute));
    } else {
        UErrorCode status = U_ZERO_ERROR;
        icuCollator->setAttribute(
            UCOL_CASE_LEVEL, boolToAttribute(collation->getCaseLevel()), status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to set '" << Collation::kCaseLevelFieldName
                                  << "' attribute: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
    }

    // Set caseFirst.
    if (!spec.hasField(Collation::kCaseFirstFieldName)) {
        UErrorCode status = U_ZERO_ERROR;
        UColAttributeValue caseFirstAttribute = icuCollator->getAttribute(UCOL_CASE_FIRST, status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to get '" << Collation::kCaseFirstFieldName
                                  << "' attribute from icu::Collator: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
        collation->setCaseFirst(getCaseFirstFromAttribute(caseFirstAttribute));
    } else {
        UErrorCode status = U_ZERO_ERROR;
        icuCollator->setAttribute(
            UCOL_CASE_FIRST, getCaseFirstAttribute(collation->getCaseFirst()), status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to set '" << Collation::kCaseFirstFieldName
                                  << "' attribute: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
    }

    // Set strength.
    if (!spec.hasField(Collation::kStrengthFieldName)) {
        UErrorCode status = U_ZERO_ERROR;
        UColAttributeValue strengthAttribute = icuCollator->getAttribute(UCOL_STRENGTH, status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to get '" << Collation::kStrengthFieldName
                                  << "' attribute from icu::Collator: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
        collation->setStrength(getStrengthFromAttribute(strengthAttribute));
    } else {
        try {
            // For backwards compatibility, "strength" is parsed from any int, long, or double.
            // Check it matches an enum value.
            CollationStrength_parse({"collation.strength"}, collation->getStrength());
        } catch (const DBException& exc) {
            return exc.toStatus();
        }

        UErrorCode status = U_ZERO_ERROR;
        icuCollator->setAttribute(
            UCOL_STRENGTH, getStrengthAttribute(collation->getStrength()), status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to set '" << Collation::kStrengthFieldName
                                  << "' attribute: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
    }

    // Set numericOrdering.
    if (!spec.hasField(Collation::kNumericOrderingFieldName)) {
        UErrorCode status = U_ZERO_ERROR;
        UColAttributeValue numericOrderingAttribute =
            icuCollator->getAttribute(UCOL_NUMERIC_COLLATION, status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to get '" << Collation::kNumericOrderingFieldName
                                  << "' attribute from icu::Collator: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
        collation->setNumericOrdering(attributeToBool(numericOrderingAttribute));
    } else {
        UErrorCode status = U_ZERO_ERROR;
        icuCollator->setAttribute(
            UCOL_NUMERIC_COLLATION, boolToAttribute(collation->getNumericOrdering()), status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to set '" << Collation::kNumericOrderingFieldName
                                  << "' attribute: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
    }

    // Set alternate.
    if (!spec.hasField(Collation::kAlternateFieldName)) {
        UErrorCode status = U_ZERO_ERROR;
        UColAttributeValue alternateAttribute =
            icuCollator->getAttribute(UCOL_ALTERNATE_HANDLING, status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to get '" << Collation::kAlternateFieldName
                                  << "' attribute from icu::Collator: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
        collation->setAlternate(getAlternateFromAttribute(alternateAttribute));
    } else {
        UErrorCode status = U_ZERO_ERROR;
        icuCollator->setAttribute(
            UCOL_ALTERNATE_HANDLING, getAlternateAttribute(collation->getAlternate()), status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to set '" << Collation::kAlternateFieldName
                                  << "' attribute: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
    }

    // Set maxVariable.
    if (!spec.hasField(Collation::kMaxVariableFieldName)) {
        collation->setMaxVariable(getMaxVariableFromReorderCode(icuCollator->getMaxVariable()));
    } else {
        UErrorCode status = U_ZERO_ERROR;
        icuCollator->setMaxVariable(getMaxVariableReorderCode(collation->getMaxVariable()), status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to set '" << Collation::kMaxVariableFieldName
                                  << "' attribute: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
    }

    // Set normalization.
    if (!spec.hasField(Collation::kNormalizationFieldName)) {
        UErrorCode status = U_ZERO_ERROR;
        UColAttributeValue normalizationAttribute =
            icuCollator->getAttribute(UCOL_NORMALIZATION_MODE, status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to get '" << Collation::kNormalizationFieldName
                                  << "' attribute from icu::Collator: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
        collation->setNormalization(attributeToBool(normalizationAttribute));
    } else {
        UErrorCode status = U_ZERO_ERROR;
        icuCollator->setAttribute(
            UCOL_NORMALIZATION_MODE, boolToAttribute(collation->getNormalization()), status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to set '" << Collation::kNormalizationFieldName
                                  << "' attribute: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
    }

    // Set backwards.
    if (!spec.hasField(Collation::kBackwardsFieldName)) {
        UErrorCode status = U_ZERO_ERROR;
        UColAttributeValue backwardsAttribute =
            icuCollator->getAttribute(UCOL_FRENCH_COLLATION, status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to get '" << Collation::kBackwardsFieldName
                                  << "' attribute from icu::Collator: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
        collation->setBackwards(attributeToBool(backwardsAttribute));
    } else {
        UErrorCode status = U_ZERO_ERROR;
        // collation->getBackwards should be engaged if spec has a "backwards" field.
        invariant(collation->getBackwards().is_initialized());
        icuCollator->setAttribute(
            UCOL_FRENCH_COLLATION, boolToAttribute(*collation->getBackwards()), status);
        if (U_FAILURE(status)) {
            icu::ErrorCode icuError;
            icuError.set(status);
            return {ErrorCodes::OperationFailed,
                    str::stream() << "Failed to set '" << Collation::kBackwardsFieldName
                                  << "' attribute: " << icuError.errorName()
                                  << ". Collation spec: " << spec};
        }
    }

    if (!collation->getVersion()) {
        collation->setVersion(StringData(U_ICU_VERSION));
    } else {
        if (U_ICU_VERSION != *collation->getVersion()) {
            return {ErrorCodes::IncompatibleCollationVersion,
                    str::stream() << "Requested collation version " << collation->getVersion()
                                  << " but the only available collator version was "
                                  << U_ICU_VERSION << ". Requested collation spec: " << spec};
        }
    }

    return Status::OK();
}

// Returns a non-OK status if any part of the locale ID is invalid or not recognized by ICU.
Status validateLocaleID(const BSONObj& spec, StringData originalID, const icu::Collator& collator) {
    UErrorCode status = U_ZERO_ERROR;
    icu::Locale collatorLocale = collator.getLocale(ULOC_VALID_LOCALE, status);
    if (U_FAILURE(status)) {
        icu::ErrorCode icuError;
        icuError.set(status);
        return {ErrorCodes::OperationFailed,
                str::stream() << "Failed to get locale from icu::Collator: " << icuError.errorName()
                              << ". Collation spec: " << spec};
    }

    if (originalID.empty()) {
        return {ErrorCodes::BadValue,
                str::stream() << "Field '" << Collation::kLocaleFieldName
                              << "' cannot be the empty string in: " << spec};
    }

    // Check that each component of the locale ID is recognized by ICU. If ICU 1) cannot parse the
    // locale id, 2) has to do any sort of locale id canonicalization, 3) does not recognize some
    // component of the locale, or 4) has no data to support some component of the locale, then the
    // resulting icu::Locale name will not match the requested locale. In this case we return an
    // error to the user. In the error message to the user, we report the locale that ICU *would
    // have* used, which the application can supply as an alternative.
    auto collatorLocaleName = StringData(collatorLocale.getName());
    if (originalID != collatorLocaleName) {
        str::stream ss;
        ss << "Field '" << Collation::kLocaleFieldName << "' is invalid in: " << spec;

        if ((collatorLocaleName != kFallbackLocaleName) && !collatorLocaleName.empty()) {
            ss << ". Did you mean '" << collatorLocaleName << "'?";
        }

        return {ErrorCodes::BadValue, ss};
    }

    return Status::OK();
}

// Returns a non-OK status if 'spec' contains any invalid combinations of options.
Status validateCollationSpec(const Collation& collation, const BSONObj& spec) {
    // The backwards option specifically means backwards secondary weighting, and therefore only
    // affects the secondary comparison level. It has no effect at strength 1.
    if (collation.getBackwards().value_or(false) &&
        static_cast<CollationStrength>(collation.getStrength()) == CollationStrength::kPrimary) {
        return {ErrorCodes::BadValue,
                str::stream() << "'" << Collation::kBackwardsFieldName << "' is invalid with '"
                              << Collation::kStrengthFieldName << "' of "
                              << static_cast<int>(CollationStrength::kPrimary) << " in: " << spec};
    }

    // The caseFirst option only affects tertiary level or caseLevel comparisons. It will have no
    // affect if caseLevel is off and strength is 1 or 2.
    if (collation.getCaseFirst() != CollationCaseFirstEnum::kOff && !collation.getCaseLevel() &&
        (static_cast<CollationStrength>(collation.getStrength()) == CollationStrength::kPrimary ||
         static_cast<CollationStrength>(collation.getStrength()) ==
             CollationStrength::kSecondary)) {
        return {ErrorCodes::BadValue,
                str::stream() << "'" << Collation::kCaseFirstFieldName << "' is invalid unless '"
                              << Collation::kCaseLevelFieldName << "' is on or '"
                              << Collation::kStrengthFieldName << "' is greater than "
                              << static_cast<int>(CollationStrength::kSecondary)
                              << " in: " << spec};
    }

    return Status::OK();
}

}  // namespace

StatusWith<std::unique_ptr<CollatorInterface>> CollatorFactoryICU::makeFromBSON(
    const BSONObj& spec) {

    Collation collation;
    try {
        collation = Collation::parse({"collation"}, spec);
    } catch (const DBException& ex) {
        return ex.toStatus();
    }

    if (collation.getLocale().find('\0') != std::string::npos) {
        return {ErrorCodes::BadValue,
                str::stream() << "Field '" << Collation::kLocaleFieldName
                              << "' cannot contain null byte. Collation spec: " << spec};
    }

    // If spec = {locale: "simple"}, return a null pointer. A null CollatorInterface indicates
    // simple binary compare.
    if (collation.getLocale() == CollationSpec::kSimpleBinaryComparison) {
        return {nullptr};
    }

    // Construct an icu::Locale.
    auto userLocale = icu::Locale::createFromName(collation.getLocale().toString().c_str());
    if (userLocale.isBogus()) {
        return {ErrorCodes::BadValue,
                str::stream() << "Field '" << Collation::kLocaleFieldName
                              << "' is not valid in: " << spec};
    }

    // Construct an icu::Collator.
    UErrorCode status = U_ZERO_ERROR;
    std::unique_ptr<icu::Collator> icuCollator(icu::Collator::createInstance(userLocale, status));
    if (U_FAILURE(status)) {
        icu::ErrorCode icuError;
        icuError.set(status);
        return {ErrorCodes::OperationFailed,
                str::stream() << "Failed to create collator: " << icuError.errorName()
                              << ". Collation spec: " << spec};
    }

    Status localeValidationStatus = validateLocaleID(spec, collation.getLocale(), *icuCollator);
    if (!localeValidationStatus.isOK()) {
        return localeValidationStatus;
    }

    // Update the Collation's options with the defaults in icuCollator.
    // Use userLocale.getName() for the localeID, since it is canonicalized and includes options.
    auto updateCollationSpecStatus = updateCollationSpecFromICUCollator(
        spec, userLocale.getName(), icuCollator.get(), &collation);
    if (!updateCollationSpecStatus.isOK()) {
        return updateCollationSpecStatus;
    }

    auto validateSpecStatus = validateCollationSpec(collation, spec);
    if (!validateSpecStatus.isOK()) {
        return validateSpecStatus;
    }

    auto mongoCollator =
        std::make_unique<CollatorInterfaceICU>(std::move(collation), std::move(icuCollator));
    return {std::move(mongoCollator)};
}

}  // namespace mongo