<commit_before>/*
 * Copyright 2013-2014 must-be.org
 *
 * 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.mustbe.consulo.msil;

import org.jetbrains.annotations.NotNull;
import org.mustbe.consulo.dotnet.psi.DotNetTypeDeclarationUtil;
import com.intellij.openapi.util.text.StringUtil;

/**
 * @author VISTALL
 * @since 22.05.14
 */
public class MsilHelper
{
	public static final String CONSTRUCTOR_NAME = ".ctor";
	public static final String STATIC_CONSTRUCTOR_NAME = ".cctor";

	@NotNull
	public static String prepareForUser(@NotNull String name)
	{
		String newName = cutGenericMarker(name);
		newName = newName.replace(DotNetTypeDeclarationUtil.NESTED_SEPARATOR_IN_GAME, DotNetTypeDeclarationUtil.NORMAL_SEPARATOR_IN_GAME);
		return newName;
	}

	@NotNull
	public static String cutGenericMarker(@NotNull String name)
	{
		int i = name.lastIndexOf(DotNetTypeDeclarationUtil.GENERIC_MARKER_IN_NAME);
		if(i > 0)
		{
			name = name.substring(0, i);
		}
		return name;
	}

	public static String appendNoGeneric(String namespace, String name)
	{
		if(StringUtil.isEmpty(namespace))
		{
			return cutGenericMarker(name);
		}
		else
		{
			return namespace + "." + cutGenericMarker(name);
		}
	}

	public static String append(String namespace, String name)
	{
		if(StringUtil.isEmpty(namespace))
		{
			return name;<commit_msg>problem with presentation for System.Collection.Generic.List`1/Enumerator fixed<commit_after>/*
 * Copyright 2013-2014 must-be.org
 *
 * 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.mustbe.consulo.msil;

import org.jetbrains.annotations.NotNull;
import org.mustbe.consulo.dotnet.psi.DotNetTypeDeclarationUtil;
import com.intellij.openapi.util.text.StringUtil;

/**
 * @author VISTALL
 * @since 22.05.14
 */
public class MsilHelper
{
	public static final String CONSTRUCTOR_NAME = ".ctor";
	public static final String STATIC_CONSTRUCTOR_NAME = ".cctor";

	@NotNull
	public static String prepareForUser(@NotNull String name)
	{
		String newName = cutGenericMarker(name);
		newName = newName.replace(DotNetTypeDeclarationUtil.NESTED_SEPARATOR_IN_GAME, DotNetTypeDeclarationUtil.NORMAL_SEPARATOR_IN_GAME);
		return newName;
	}

	@NotNull
	public static String cutGenericMarker(@NotNull String name)
	{
		int nested = name.lastIndexOf(DotNetTypeDeclarationUtil.NESTED_SEPARATOR_IN_GAME);
		int i = name.lastIndexOf(DotNetTypeDeclarationUtil.GENERIC_MARKER_IN_NAME);
		if(i > 0)
		{
			// if we dont have nested like System.Collection.Generic.List`1
			if(nested == -1)
			{
				name = name.substring(0, i);
			}
			// if we have nested like System.Collection.Generic.List`1/Enumerator
			else
			{
				StringBuilder builder = new StringBuilder(name.length() - 2);
				char[] chars = name.toCharArray();

				boolean genericEntered = false;
				for(char aChar : chars)
				{
					switch(aChar)
					{
						case '`':
							genericEntered = true;
							break;
						case '/':
							aChar = '.';
						default:
							if(genericEntered)
							{
								if(Character.isDigit(aChar))
								{
									continue;
								}
								else
								{
									genericEntered = false;
								}
							}
							builder.append(aChar);
							break;
					}
				}
				name = builder.toString();
			}
		}
		return name;
	}

	public static String appendNoGeneric(String namespace, String name)
	{
		if(StringUtil.isEmpty(namespace))
		{
			return cutGenericMarker(name);
		}
		else
		{
			return namespace + "." + cutGenericMarker(name);
		}
	}

	public static String append(String namespace, String name)
	{
		if(StringUtil.isEmpty(namespace))
		{
			return name;
{'fraction_non_alphanumeric': 0.09507271543303668, 'fraction_numerical': 0.009767744736270892, 'mean_word_length': 3.608, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3015942', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1391, 'n_words': 385}