github.com/boki/go-xmp@v1.0.1/models/riff/types.go (about)

     1  // Copyright (c) 2017-2018 Alexander Eichhorn
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"): you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    11  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    12  // License for the specific language governing permissions and limitations
    13  // under the License.
    14  
    15  package riff
    16  
    17  import (
    18  	"strings"
    19  	"trimmer.io/go-xmp/xmp"
    20  )
    21  
    22  type StringArray xmp.StringArray
    23  
    24  func (a StringArray) Typ() xmp.ArrayType {
    25  	return xmp.ArrayTypeUnordered
    26  }
    27  
    28  func (x *StringArray) UnmarshalText(data []byte) error {
    29  	*x = strings.Split(string(data), "; ")
    30  	return nil
    31  }
    32  
    33  func (x StringArray) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error {
    34  	return xmp.MarshalArray(e, node, x.Typ(), x)
    35  }
    36  
    37  func (x *StringArray) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error {
    38  	return xmp.UnmarshalArray(d, node, x.Typ(), x)
    39  }
    40  
    41  type AltString xmp.AltString
    42  
    43  func (x *AltString) UnmarshalText(data []byte) error {
    44  	as := xmp.AltString{}
    45  	for _, v := range strings.Split(string(data), "; ") {
    46  		as.Add("eng", v)
    47  	}
    48  	*x = AltString(as)
    49  	return nil
    50  }
    51  
    52  func (x AltString) Typ() xmp.ArrayType {
    53  	return xmp.ArrayTypeAlternative
    54  }
    55  
    56  func (x AltString) MarshalXMP(e *xmp.Encoder, node *xmp.Node, m xmp.Model) error {
    57  	return xmp.MarshalArray(e, node, xmp.AltString(x).Typ(), xmp.AltString(x))
    58  }
    59  
    60  func (x *AltString) UnmarshalXMP(d *xmp.Decoder, node *xmp.Node, m xmp.Model) error {
    61  	return xmp.UnmarshalArray(d, node, xmp.AltString(*x).Typ(), (*xmp.AltString)(x))
    62  }