PHP 8.2.30
Preview: unaccent.cpp Size: 1.77 KB
/proc/self/root/opt/alt/alt-nodejs20/root/usr/share/doc/alt-nodejs20-libicu-devel/samples/translit/unaccent.cpp

/**********************************************************************
 * © 2016 and later: Unicode, Inc. and others.
 * License & terms of use: http://www.unicode.org/copyright.html
 **********************************************************************
 **********************************************************************
 * COPYRIGHT:
 * Copyright (c) 1999-2003, International Business Machines Corporation and
 * others. All Rights Reserved.
 **********************************************************************/

#include "unaccent.h"

const char UnaccentTransliterator::fgClassID = 0;

/**
 * Constructor
 */
UnaccentTransliterator::UnaccentTransliterator() :
    normalizer("", UNORM_NFD),
    Transliterator("Unaccent", nullptr) {
}

/**
 * Destructor
 */
UnaccentTransliterator::~UnaccentTransliterator() {
}

/**
 * Remove accents from a character using Normalizer.
 */
char16_t UnaccentTransliterator::unaccent(char16_t c) const {
    UnicodeString str(c);
    UErrorCode status = U_ZERO_ERROR;
    UnaccentTransliterator* t = const_cast<UnaccentTransliterator*>(this);

    t->normalizer.setText(str, status);
    if (U_FAILURE(status)) {
        return c;
    }
    return static_cast<char16_t>(t->normalizer.next());
}

/**
 * Implement Transliterator API
 */
void UnaccentTransliterator::handleTransliterate(Replaceable& text,
                                                 UTransPosition& index,
                                                 UBool incremental) const {
    UnicodeString str("a");
    while (index.start < index.limit) {
        char16_t c = text.charAt(index.start);
        char16_t d = unaccent(c);
        if (c != d) {
            str.setCharAt(0, d);
            text.handleReplaceBetween(index.start, index.start+1, str);
        }
        index.start++;
    }
}

Directory Contents

Dirs: 1 × Files: 10

Name Size Perms Modified Actions
answers DIR
- drwxr-xr-x 2025-07-31 07:07:20
Edit Download
3.92 KB lrw-r--r-- 2025-03-13 18:31:23
Edit Download
630 B lrw-r--r-- 2025-03-13 18:31:23
Edit Download
3.83 KB lrw-r--r-- 2025-03-13 18:31:23
Edit Download
1.18 KB lrw-r--r-- 2025-03-13 18:31:23
Edit Download
7.67 KB lrw-r--r-- 2025-03-13 18:31:23
Edit Download
1.15 KB lrw-r--r-- 2025-03-13 18:31:23
Edit Download
1.77 KB lrw-r--r-- 2025-03-13 18:31:23
Edit Download
2.87 KB lrw-r--r-- 2025-03-13 18:31:23
Edit Download
2.25 KB lrw-r--r-- 2025-03-13 18:31:23
Edit Download
872 B lrw-r--r-- 2025-03-13 18:31:23
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).