// Copyright (c) 2015-2021 Martin Hensel
// Copyright (c) 2026 luo-studio
// Copyright (c) 2026 erweixin (upstream RaTeX)
// SPDX-License-Identifier: Apache-2.0 AND MIT
//
// Go translation and modification of mhchemparser 4.1.1. Initial Go
// translation structure adapted from github.com/Luo-Studio/go-tex (MIT).

// Package mhchem ports mhchemparser 4.1.1, the parser used by MathJax 3.2.2. // ToTeX converts \ce and \pu source into a TeX expansion for a host parser.
package mhchem // Buffer mirrors the mhchemparser buffer object used by the action // handlers in actions.go. Slots a..rm are typed as *string so we can // distinguish "unset" from "empty string". type Buffer struct { ParenthesisLevel int BeginsWithBond bool Sb bool A *string B *string P *string O *string Q *string D *string DType *string R *string Rdt *string Rd *string Rqt *string Rq *string Text *string Rm *string } // NewBuffer returns a fresh, zeroed Buffer. func () *Buffer { return &Buffer{} } // ClearSoft clears all slots except ParenthesisLevel/BeginsWithBond. func ( *Buffer) () { .Sb = false .A, .B, .P, .O, .Q = nil, nil, nil, nil, nil .D, .DType, .R = nil, nil, nil .Rdt, .Rd, .Rqt, .Rq = nil, nil, nil, nil .Text, .Rm = nil, nil } // ClearAll resets the buffer to its zero value. func ( *Buffer) () { * = Buffer{} } // IsSlotEmpty reports whether s is nil or points to an empty string. func ( *string) bool { return == nil || * == "" } // SetSlot writes v to *slot, allocating if nil. func ( **string, string) { if * == nil { := * = & return } ** = }