// Path: fixb/src/main/java/org/fixb/impl/FormatConstants.java
// public static final char SOH = 0x01;


import java.util.HashMap;
import java.util.Map;
import static org.fixb.impl.FormatConstants.SOH;
/*
 * Copyright 2013 YTEQ Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.fixb.impl;



/**
 * Can extract separate tag values from a FIX message string while keeping track of the read position in it. It is used
 * in the implementation of NativeFixFieldExtractor.
 *
 * @author vladyslav.yatsenko
 */
public class FieldCursor {
    private Map<Integer, String> buffer = new HashMap<Integer, String>();
    private int lastPosition = -1;
    private int lastTag;

    final String fixMessage;
    String lastValue;

    /**
     * A static factory method.
     *
     * @param fixMessage a string representing FIX message
     * @return a new instance of FieldCursor based on the given FIX message.
     */
    public static FieldCursor create(String fixMessage) {
        return new FieldCursor(fixMessage);
    }

    /**
     * @return the last read FIX field value.
     */
    public String lastValue() {
        return lastValue;
    }

    /**
     * @return the last read FIX tag.
     */
    public int lastTag() {
        return lastTag;
    }

    /**
     * Reads the next FIX field in the message and updates the last read field tag and value if available.
     *
     * @return <code>true</code> if next field could be read, <code>false</code> if reached the end of message.
     */
    public boolean nextField() {
        final int start = lastPosition == -1 ? 0 : lastPosition;
        final int interim = fixMessage.indexOf('=', start);

        if (interim == -1) {
            lastTag = 0;
            lastValue = null;
            lastPosition = fixMessage.length();
            return false;
        }

// Path: fixb/src/main/java/org/fixb/impl/FormatConstants.java
// public static final char SOH = 0x01;


// Path: fixb/src/main/java/org/fixb/impl/FieldCursor.java
import java.util.HashMap;
import java.util.Map;
import static org.fixb.impl.FormatConstants.SOH;

/*
 * Copyright 2013 YTEQ Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.fixb.impl;



/**
 * Can extract separate tag values from a FIX message string while keeping track of the read position in it. It is used
 * in the implementation of NativeFixFieldExtractor.
 *
 * @author vladyslav.yatsenko
 */
public class FieldCursor {
    private Map<Integer, String> buffer = new HashMap<Integer, String>();
    private int lastPosition = -1;
    private int lastTag;

    final String fixMessage;
    String lastValue;

    /**
     * A static factory method.
     *
     * @param fixMessage a string representing FIX message
     * @return a new instance of FieldCursor based on the given FIX message.
     */
    public static FieldCursor create(String fixMessage) {
        return new FieldCursor(fixMessage);
    }

    /**
     * @return the last read FIX field value.
     */
    public String lastValue() {
        return lastValue;
    }

    /**
     * @return the last read FIX tag.
     */
    public int lastTag() {
        return lastTag;
    }

    /**
     * Reads the next FIX field in the message and updates the last read field tag and value if available.
     *
     * @return <code>true</code> if next field could be read, <code>false</code> if reached the end of message.
     */
    public boolean nextField() {
        final int start = lastPosition == -1 ? 0 : lastPosition;
        final int interim = fixMessage.indexOf('=', start);

        if (interim == -1) {
            lastTag = 0;
            lastValue = null;
            lastPosition = fixMessage.length();
            return false;
        }

        final int end = fixMessage.indexOf(SOH, interim + 1);