Source code for pyspssio.header

# -*- coding: utf-8 -*-
# =============================================================================
# COPYRIGHT NOTICE
# =============================================================================
#
# Copyright (c) 2022 Steven Spector
#
# The pyspssio python package is distributed under the MIT license,
# EXCLUDING files from the IBM I/O Modules for SPSS Statistics
# which are covered under a different license.
#
# License information pertaining to the IBM I/O Modules for SPSS Statistics
# is available in the LICENSE document.
# =============================================================================

import re

from ctypes import *

from .errors import warn_or_raise
from .constants import *
from .constants_map import *
from .spssfile import SPSSFile


def varformat_to_tuple(varformat):
    """Convert variable format as string to tuple of integers"""

    if not isinstance(varformat, str):
        return varformat

    f_split = re.split(r"([^\d]+)|[\.]", varformat + ".0")

    f_type = spss_formats_simple_rev[f_split[1]]
    f_width = int(f_split[2])
    f_dec = int(f_split[4])

    return (f_type, f_width, f_dec)