#!/usr/bin/env python


N = 128
vals = [-1]*N
for i in range(N):
    ch = chr(i)
    if 'A' <= ch <= 'Z':
        vals[i] = i - ord('A')
    elif 'a' <= ch <= 'z':
        vals[i] = i - ord('a')

vals2 = [v+1 if v != -1 else v for v in vals]


def fmtgrp(grp):
    return [f"{g:2d}" for g in grp]


def groupby(vals):
    groupsz = 16
    grps = []
    grp = []
    for v in vals:
        if len(grp) >= groupsz:
            grps.append(fmtgrp(grp))
            grp = []
        grp.append(v)
    if grp:
        grps.append(fmtgrp(grp))
    return grps



grps1 = groupby(vals)
grps2 = groupby(vals2)

# ----------------------------------------------------------------------------

print("""#pragma once

#include <cassert>

// Generated by mkiconv.py. Do not edit by hand.
""")

#
# iconv table
#
print(f"constexpr int iconv_table[{len(vals)}] = {{")
for grp in grps1:
    print(f"    {', '.join(grp)},")
print("};")

#
# sconv table
#
print(f"constexpr int sconv_table[{len(vals)}] = {{")
for grp in grps2:
    print(f"    {', '.join(grp)},")
print("};")


print("""
constexpr int iconv(char c) noexcept {
#ifndef NDEBUG
    assert(('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));
    return iconv_table[static_cast<unsigned char>(c & 0x7Fu)];
#else
    return iconv_table[static_cast<unsigned char>(c)];
#endif
}


constexpr int sconv(char c) noexcept {
#ifndef NDEBUG
    assert(('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));
    return sconv_table[static_cast<unsigned char>(c & 0x7Fu)];
#else
    return sconv_table[static_cast<unsigned char>(c)];
#endif
}
""")


#!/usr/bin/env python


N = 128
vals = [-1]*N
for i in range(N):
    ch = chr(i)
    if 'A' <= ch <= 'Z':
        vals[i] = i - ord('A')
    elif 'a' <= ch <= 'z':
        vals[i] = i - ord('a')

vals2 = [v+1 if v != -1 else v for v in vals]


def fmtgrp(grp):
    return [f"{g:2d}" for g in grp]


def groupby(vals):
    groupsz = 16
    grps = []
    grp = []
    for v in vals:
        if len(grp) >= groupsz:
            grps.append(fmtgrp(grp))
            grp = []
        grp.append(v)
    if grp:
        grps.append(fmtgrp(grp))
    return grps



grps1 = groupby(vals)
grps2 = groupby(vals2)

# ----------------------------------------------------------------------------

print("""#pragma once

#include <cassert>

// Generated by mkiconv.py. Do not edit by hand.
""")

#
# iconv table
#
print(f"constexpr int iconv_table[{len(vals)}] = {{")
for grp in grps1:
    print(f"    {', '.join(grp)},")
print("};")

#
# sconv table
#
print(f"constexpr int sconv_table[{len(vals)}] = {{")
for grp in grps2:
    print(f"    {', '.join(grp)},")
print("};")


print("""
constexpr int iconv(char c) noexcept {
#ifndef NDEBUG
    assert(('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));
    return iconv_table[static_cast<unsigned char>(c & 0x7Fu)];
#else
    return iconv_table[static_cast<unsigned char>(c)];
#endif
}


constexpr int sconv(char c) noexcept {
#ifndef NDEBUG
    assert(('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));
    return sconv_table[static_cast<unsigned char>(c & 0x7Fu)];
#else
    return sconv_table[static_cast<unsigned char>(c)];
#endif
}
""")


#!/usr/bin/env python # ---------------------------------------------------------------------------- #pragma once  #include <cassert>  // Generated by mkiconv.py. Do not edit by hand. # # iconv table # # # sconv table # constexpr int iconv(char c) noexcept { #ifndef NDEBUG     assert(('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));     return iconv_table[static_cast<unsigned char>(c & 0x7Fu)]; #else     return iconv_table[static_cast<unsigned char>(c)]; #endif }   constexpr int sconv(char c) noexcept { #ifndef NDEBUG     assert(('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));     return sconv_table[static_cast<unsigned char>(c & 0x7Fu)]; #else     return sconv_table[static_cast<unsigned char>(c)]; #endif }