Package de.sebastianbenz.task.util

Source Code of de.sebastianbenz.task.util.Contents

package de.sebastianbenz.task.util;

import org.eclipse.xtext.nodemodel.ICompositeNode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;

import de.sebastianbenz.task.Content;
import de.sebastianbenz.task.tagging.Region;

public class Contents {

  public static int offset(Content content) {
    ICompositeNode node = NodeModelUtils.getNode(content);
    return node.getOffset() + content.getIntend().length();
  }
 
  public static Region region(Content content) {
    ICompositeNode node = NodeModelUtils.getNode(content);
    String text = node.getText();
    int begin = 0;
    for (; begin < text.length(); begin++) {
      if (text.charAt(begin) != ' '
          && text.charAt(begin) != '\t') {
        break;
      }
    }
    int end = text.length()-1;
    for(; end >= 0; end--){
      if(text.charAt(end) != ' '
          && text.charAt(end) != '\t'){
        break;
      }
    }
    return Region.create(node.getOffset() + begin, end - begin);
  }

}
TOP

Related Classes of de.sebastianbenz.task.util.Contents

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.