GVKun编程网logo

iphone – NSString的stringByAppendingPathComponent:在http://中删除’/’(nsstring stringwithformat)

13

在这篇文章中,我们将为您详细介绍iphone–NSString的stringByAppendingPathComponent:在http://中删除’/’的内容,并且讨论关于nsstringstrin

在这篇文章中,我们将为您详细介绍iphone – NSString的stringByAppendingPathComponent:在http://中删除’/’的内容,并且讨论关于nsstring stringwithformat的相关问题。此外,我们还会涉及一些关于CGMH:Constrained Sentence Generation by Metropolis-Hastings Sampling解读、com.intellij.openapi.components.TrackingPathMacroSubstitutor的实例源码、ios – NSURL:URLByAppendingPathComponent:转换?进入?,但随后UIWebView撤消了转换导致的负载故障、ios – 带有条件的[NSArray componentsJoinedByString]的知识,以帮助您更全面地了解这个主题。

本文目录一览:

iphone – NSString的stringByAppendingPathComponent:在http://中删除’/’(nsstring stringwithformat)

iphone – NSString的stringByAppendingPathComponent:在http://中删除’/’(nsstring stringwithformat)

我一直在修改一些代码在Mac OS X和iPhone操作系统之间工作。

我遇到了一些使用NSURL的URLByAppendingPathComponent的代码:(10.6中添加),有些人可能会知道这些代码在iPhone SDK中不可用。

我的解决方案使这个代码在操作系统之间工作是使用

Nsstring *urlString = [myURL absoluteString];
urlString = [urlString stringByAppendingPathComponent:@"helloworld"];
myURL = [NSURL urlWithString:urlString];

这样做的问题是Nsstring的stringByAppendingPathComponent:似乎从URL的http://部分删除了一个/。

这是有意的行为还是一个错误?

编辑

好的,所以我问了上面的问题有点太快了。我重新阅读了文件,它说:

Note that this method only works with file paths (not,for example,string representations of URLs)

但是,如果您需要将路径组件添加到iPhone上的URL,则它不会给出正确方向上的任何指针,要做什么,请执行以下操作:

我可以随时手动进行操作,添加/如果需要和额外的字符串,但我希望保持它尽可能接近原始的Mac OS X代码…

解决方法

我将在NSURL上实现一个myURLByAppendingPathComponent:方法,这样做也是一样。给它一个不同名称的原因是,当苹果公司将10.6 API移植到iPhone时,它不会覆盖苹果提供的方法(所以“我的”仅仅是一个例子 – 关键是它不太可能有人否则会写一个这个名字的方法)。

在我看来,你只想混乱路径而不是整个网址。这是一个未经测试的示例:

- (NSURL *)myURLByAppendingPathComponent:(Nsstring *)component {
    Nsstring *newPath = [[self path] stringByAppendingPathComponent:component];
    return [[[NSURL alloc] initWithScheme: [self scheme] 
                                     host: [self host] 
                                     path: newPath]
                                     autorelease];
}

它只能与具有类似文件的路径的URL正常工作,但我很确定Apple方法的工作方式相同。无论如何,希望它能帮助你正确的方向。

CGMH:Constrained Sentence Generation by Metropolis-Hastings Sampling解读

CGMH:Constrained Sentence Generation by Metropolis-Hastings Sampling解读

 

 

根据关键字生成句子:

读进关键字,随机选择处理手段(增删改)以及待处理word的位置,然后计算接受/拒绝概率,根据概率生成一个新的序列,再循环这一过程,循环次数是500,每次都将困惑度最低的生成句子放在列表中第一个位置,最后根据config设置的最短长度(如7),当列表中的一个句子长度大于7时,则将该句子输出,作为最终生成的句子。


其中,计算接受/拒绝概率的方法:

先计算一个句子的固定分布:(=语言模型中该句的概率*关键字的指示函数)

再计算某个token被接受的概率:

 

论文翻译:

1.MH采样的框架:包括建议设计,固定分布,接受决定

1)温和条件下,样本得分不会瘦脸为马尔科夫链的固定分布。所以,目的是设计一个马尔科夫链,其固定分布是想要的句子分布。

首先,MH采样器分两步解决这个问题:一是提出一个实验性转换,根据接受率来接受或者拒绝一个建议。接受/拒绝率通过想要的固定分布和建议的固定分布来计算,这确保了细节平衡条件,该条件保证MH收敛到想要的分布。

π(x)表示我们想要从中取样的句子的分布(x表示一个特定的句子)。MH从任意状态x0开始(一个出示句子或 一系列关键字),在每个步骤t,根据建议的分布g(x’|x_t-1),提出一个新的句子x‘,其中x_t-1表示最后一步的句子。

 

据公式(1),获得一个概率,如果根据该概率A,一个建议应该被接受,则下一个句子x_t = x’,否则,

 

根据概率1-A,一个建议应该被拒绝,则x_t = x_t-1。理论上,对于一个不可再分的且非周期性的马尔科夫链来说,当n趋于无穷时,样本x_n的分布会收敛到π(x)。实际上,初始的几个样本会被丢弃。如果样本收敛到固定分布,则该马尔科夫链建立完成。

 

 

 

 

 

 

2

2.根据关键字生成句子实验

使用500万句子训练出一个语言模型,使用该语言模型训练CGMH模型

输入:使用3000个句子提供关键字,用来测试。对于每个句子,随机采样一个或者多个words作为限制条件。

输出:对于MH采样,我们使用关键字序列作为初始状态,然后选择100步后有最低困惑度(即流畅度最高)的语句作为输出。

 

 

com.intellij.openapi.components.TrackingPathMacroSubstitutor的实例源码

com.intellij.openapi.components.TrackingPathMacroSubstitutor的实例源码

项目:intellij-ce-playground    文件:StorageUtil.java   
private static void doNotify(@NotNull final Set<String> macros,@NotNull final Project project,@NotNull final Map<TrackingPathMacroSubstitutor,IComponentStore> substitutorToStore) {
  String format = "<p><i>%s</i> %s undefined. <a href=\"define\">Fix it</a></p>";
  String productName = ApplicationNamesInfo.getInstance().getProductName();
  String content = String.format(format,StringUtil.join(macros,","),macros.size() == 1 ? "is" : "are") +
                   "<br>Path variables are used to substitute absolute paths " +
                   "in " + productName + " project files " +
                   "and allow project file sharing in version control systems.<br>" +
                   "Some of the files describing the current project settings contain unkNown path variables " +
                   "and " + productName + " cannot restore those paths.";
  new UnkNownMacroNotification("Load Error","Load error: undefined path variables",content,NotificationType.ERROR,new NotificationListener() {
                                 @Override
                                 public void hyperlinkUpdate(@NotNull Notification notification,@NotNull HyperlinkEvent event) {
                                   checkUnkNownMacros(project,true,macros,substitutorToStore);
                                 }
                               },macros).notify(project);
}
项目:intellij-ce-playground    文件:StorageUtil.java   
public static void checkUnkNownMacros(@NotNull Project project,boolean notify) {
  // use linked set/map to get stable results
  Set<String> unkNownMacros = new LinkedHashSet<String>();
  Map<TrackingPathMacroSubstitutor,IComponentStore> substitutorToStore = ContainerUtil.newLinkedHashMap();
  collect(project,unkNownMacros,substitutorToStore);
  for (Module module : ModuleManager.getInstance(project).getModules()) {
    collect(module,substitutorToStore);
  }

  if (unkNownMacros.isEmpty()) {
    return;
  }

  if (notify) {
    doNotify(unkNownMacros,project,substitutorToStore);
    return;
  }

  checkUnkNownMacros(project,false,substitutorToStore);
}
项目:intellij-ce-playground    文件:StorageUtil.java   
private static void collect(@NotNull ComponentManager componentManager,@NotNull  Set<String> unkNownMacros,@NotNull Map<TrackingPathMacroSubstitutor,IComponentStore> substitutorToStore) {
  IComponentStore store = ServiceKt.getStateStore(componentManager);
  TrackingPathMacroSubstitutor substitutor = store.getStateStorageManager().getMacroSubstitutor();
  if (substitutor == null) {
    return;
  }

  Set<String> macros = substitutor.getUnkNownMacros(null);
  if (macros.isEmpty()) {
    return;
  }

  unkNownMacros.addAll(macros);
  substitutorToStore.put(substitutor,store);
}
项目:intellij-ce-playground    文件:FileStorageCoreUtil.java   
@NotNull
public static TreeMap<String,Element> load(@NotNull Element rootElement,@Nullable PathMacroSubstitutor pathMacroSubstitutor,boolean intern) {
  if (pathMacroSubstitutor != null) {
    pathMacroSubstitutor.expandpaths(rootElement);
  }

  StringInterner interner = intern ? new StringInterner() : null;
  List<Element> children = rootElement.getChildren(COMPONENT);
  TreeMap<String,Element> map = new TreeMap<String,Element>();
  for (Element element : children) {
    String name = getComponentNameIfValid(element);
    if (name == null || !(element.getAttributes().size() > 1 || !element.getChildren().isEmpty())) {
      continue;
    }

    if (interner != null) {
      JDOMUtil.internElement(element,interner);
    }

    map.put(name,element);

    if (pathMacroSubstitutor instanceof TrackingPathMacroSubstitutor) {
      ((TrackingPathMacroSubstitutor)pathMacroSubstitutor).addUnkNownMacros(name,PathMacrosCollector.getMacroNames(element));
    }

    // remove only after "getMacroNames" - some PathMacroFilter requires element name attribute
    element.removeAttribute(NAME);
  }
  return map;
}
项目:intellij-ce-playground    文件:StorageUtil.java   
public static void notifyUnkNownMacros(@NotNull final IComponentStore store,@NotNull final String componentName) {
  final TrackingPathMacroSubstitutor substitutor = store.getStateStorageManager().getMacroSubstitutor();
  if (substitutor == null) {
    return;
  }

  Set<String> immutableMacros = substitutor.getUnkNownMacros(componentName);
  if (immutableMacros.isEmpty()) {
    return;
  }

  final Set<String> macros = new LinkedHashSet<String>(immutableMacros);
  AppUIUtil.invokeOnEdt(new Runnable() {
    @Override
    public void run() {
      List<String> notified = null;
      NotificationsManager manager = NotificationsManager.getNotificationsManager();
      for (UnkNownMacroNotification notification : manager.getNotificationsOfType(UnkNownMacroNotification.class,project)) {
        if (notified == null) {
          notified = new SmartList<String>();
        }
        notified.addAll(notification.getMacros());
      }
      if (!ContainerUtil.isEmpty(notified)) {
        macros.removeAll(notified);
      }

      if (macros.isEmpty()) {
        return;
      }

      LOG.debug("Reporting unkNown path macros " + macros + " in component " + componentName);
      doNotify(macros,Collections.singletonMap(substitutor,store));
    }
  },project.getdisposed());
}
项目:tools-idea    文件:StorageData.java   
public void checkUnkNownMacros(TrackingPathMacroSubstitutor pathMacroSubstitutor) {
  if (pathMacroSubstitutor == null) return;

  for (String componentName : myComponentStates.keySet()) {
    final Set<String> unkNownMacros = PathMacrosCollector.getMacroNames(myComponentStates.get(componentName));
    if (!unkNownMacros.isEmpty()) {
      pathMacroSubstitutor.addUnkNownMacros(componentName,unkNownMacros);
    }
  }
}
项目:tools-idea    文件:StorageUtil.java   
public static void notifyUnkNownMacros(@NotNull TrackingPathMacroSubstitutor substitutor,@Nullable String componentName) {
  final LinkedHashSet<String> macros = new LinkedHashSet<String>(substitutor.getUnkNownMacros(componentName));
  if (macros.isEmpty()) {
    return;
  }

  UIUtil.invokelaterIfNeeded(new Runnable() {
    public void run() {
      macros.removeAll(getMacrosFromExistingNotifications(project));

      if (!macros.isEmpty()) {
        String format = "<p><i>%s</i> %s undefined. <a href=\"define\">Fix it</a></p>";
        String productName = ApplicationNamesInfo.getInstance().getProductName();
        String content = String.format(format,macros.size() == 1 ? "is" : "are") +
                         "<br>Path variables are used to substitute absolute paths " +
                         "in " + productName + " project files " +
                         "and allow project file sharing in version control systems.<br>" +
                         "Some of the files describing the current project settings contain unkNown path variables " +
                         "and " + productName + " cannot restore those paths.";
        new UnkNownMacroNotification("Load Error",new NotificationListener() {
                                       public void hyperlinkUpdate(@NotNull Notification notification,@NotNull HyperlinkEvent event) {
                                         ((ProjectEx)project).checkUnkNownMacros(true);
                                       }
                                     },macros).notify(project);
      }
    }
  });
}
项目:tools-idea    文件:ProjectWithModulesstoreImpl.java   
@Override
public TrackingPathMacroSubstitutor[] getSubstitutors() {
  final List<TrackingPathMacroSubstitutor> result = new ArrayList<TrackingPathMacroSubstitutor>();
  result.add(getStateStorageManager().getMacroSubstitutor());

  for (Module module : getPersistentModules()) {
    result.add(((ModuleImpl)module).getStateStore().getStateStorageManager().getMacroSubstitutor());
  }

  return result.toArray(new TrackingPathMacroSubstitutor[result.size()]);
}
项目:consulo    文件:StorageUtil.java   
public static void notifyUnkNownMacros(@Nonnull TrackingPathMacroSubstitutor substitutor,@Nonnull final Project project,@Nullable final String componentName) {
  final LinkedHashSet<String> macros = new LinkedHashSet<String>(substitutor.getUnkNownMacros(componentName));
  if (macros.isEmpty()) {
    return;
  }

  UIUtil.invokelaterIfNeeded(new Runnable() {
    @Override
    public void run() {
      macros.removeAll(getMacrosFromExistingNotifications(project));

      if (!macros.isEmpty()) {
        LOG.debug("Reporting unkNown path macros " + macros + " in component " + componentName);
        String format = "<p><i>%s</i> %s undefined. <a href=\"define\">Fix it</a></p>";
        String productName = ApplicationNamesInfo.getInstance().getProductName();
        String content = String.format(format,(notification,event) -> ((ProjectEx)project).checkUnkNownMacros(true),macros).notify(project);
      }
    }
  });
}
项目:consulo    文件:StorageData.java   
public void load(@Nonnull Element rootElement,boolean intern) {
  if (pathMacroSubstitutor != null) {
    pathMacroSubstitutor.expandpaths(rootElement);
  }

  StringInterner interner = intern ? new StringInterner() : null;
  for (Iterator<Element> iterator = rootElement.getChildren(COMPONENT).iterator(); iterator.hasNext(); ) {
    Element element = iterator.next();
    String name = getComponentNameIfValid(element);
    if (name == null || !(element.getAttributes().size() > 1 || !element.getChildren().isEmpty())) {
      continue;
    }

    iterator.remove();
    if (interner != null) {
      JDOMUtil.internStringsInElement(element,interner);
    }

    myStates.put(name,PathMacrosService.getInstance().getMacroNames(element));
    }

    // remove only after "getMacroNames" - some PathMacroFilter requires element name attribute
    element.removeAttribute(NAME);
  }
}
项目:consulo    文件:XmlElementStorage.java   
protected XmlElementStorage(@Nonnull String fileSpec,@Nullable RoamingType roamingType,@Nullable TrackingPathMacroSubstitutor pathMacroSubstitutor,@Nonnull String rootElementName,@Nullable StreamProvider streamProvider) {
  super(pathMacroSubstitutor);

  myFileSpec = fileSpec;
  myRoamingType = roamingType == null ? RoamingType.PER_USER : roamingType;
  myRootElementName = rootElementName;
  myStreamProvider = myRoamingType == RoamingType.disABLED ? null : streamProvider;
}
项目:intellij-ce-playground    文件:DirectoryStorageUtil.java   
@NotNull
public static Map<String,Element> loadFrom(@Nullable VirtualFile dir,@Nullable TrackingPathMacroSubstitutor pathMacroSubstitutor) {
  if (dir == null || !dir.exists()) {
    return Collections.emptyMap();
  }

  StringInterner interner = new StringInterner();
  Map<String,Element> filetoState = new THashMap<String,Element>();
  for (VirtualFile file : dir.getChildren()) {
    // ignore system files like .DS_Store on Mac
    if (!StringUtilRt.endsWithIgnoreCase(file.getNameSequence(),FileStorageCoreUtil.DEFAULT_EXT)) {
      continue;
    }

    try {
      if (file.getLength() == 0) {
        LOG.warn("Ignore empty file " + file.getPath());
        continue;
      }

      Element element = JDOMUtil.load(file.getInputStream());
      String componentName = FileStorageCoreUtil.getComponentNameIfValid(element);
      if (componentName == null) {
        continue;
      }

      if (!element.getName().equals(FileStorageCoreUtil.COMPONENT)) {
        LOG.error("Incorrect root tag name (" + element.getName() + ") in " + file.getPresentableurl());
        continue;
      }

      List<Element> elementChildren = element.getChildren();
      if (elementChildren.isEmpty()) {
        continue;
      }

      Element state = (Element)elementChildren.get(0).detach();
      if (JDOMUtil.isEmpty(state)) {
        continue;
      }

      JDOMUtil.internElement(state,interner);
      if (pathMacroSubstitutor != null) {
        pathMacroSubstitutor.expandpaths(state);
        pathMacroSubstitutor.addUnkNownMacros(componentName,PathMacrosCollector.getMacroNames(state));
      }

      filetoState.put(file.getName(),state);
    }
    catch (Throwable e) {
      LOG.warn("Unable to load state",e);
    }
  }
  return filetoState;
}
项目:intellij-ce-playground    文件:BasePathMacroManager.java   
@NotNull
@Override
public TrackingPathMacroSubstitutor createTrackingSubstitutor() {
  return new MyTrackingPathMacroSubstitutor();
}
项目:intellij-ce-playground    文件:StorageUtil.java   
private static void checkUnkNownMacros(@NotNull Project project,boolean showDialog,@NotNull Set<String> unkNownMacros,IComponentStore> substitutorToStore) {
  if (unkNownMacros.isEmpty() || (showDialog && !ProjectMacrosUtil.checkMacros(project,new THashSet<String>(unkNownMacros)))) {
    return;
  }

  PathMacros pathMacros = PathMacros.getInstance();
  for (Iterator<String> it = unkNownMacros.iterator(); it.hasNext(); ) {
    String macro = it.next();
    if (StringUtil.isEmptyOrSpaces(pathMacros.getValue(macro)) && !pathMacros.isIgnoredMacroName(macro)) {
      it.remove();
    }
  }

  if (unkNownMacros.isEmpty()) {
    return;
  }

  for (Map.Entry<TrackingPathMacroSubstitutor,IComponentStore> entry : substitutorToStore.entrySet()) {
    TrackingPathMacroSubstitutor substitutor = entry.getKey();
    Set<String> components = substitutor.getComponents(unkNownMacros);
    IComponentStore store = entry.getValue();
    if (store.isReloadPossible(components)) {
      substitutor.invalidateUnkNownMacros(unkNownMacros);

      for (UnkNownMacroNotification notification : NotificationsManager.getNotificationsManager().getNotificationsOfType(UnkNownMacroNotification.class,project)) {
        if (unkNownMacros.containsAll(notification.getMacros())) {
          notification.expire();
        }
      }

      store.reloadStates(components,project.getMessageBus());
    }
    else if (Messages.showYesNoDialog(project,"Component Could not be reloaded. Reload project?","Configuration Changed",Messages.getQuestionIcon()) == Messages.YES) {
      ProjectManagerEx.getInstanceEx().reloadProject(project);
    }
  }
}
项目:tools-idea    文件:BasePathMacroManager.java   
@Override
public TrackingPathMacroSubstitutor createTrackingSubstitutor() {
  return new MyTrackingPathMacroSubstitutor();
}
项目:tools-idea    文件:MockProjectStore.java   
@Override
public TrackingPathMacroSubstitutor[] getSubstitutors() {
  return new TrackingPathMacroSubstitutor[0];
}
项目:tools-idea    文件:ProjectManagerImpl.java   
@Override
public boolean openProject(final Project project) {
  if (isLight(project)) {
    throw new AssertionError("must not open light project");
  }
  final Application application = ApplicationManager.getApplication();

  if (!application.isUnitTestMode() && !((ProjectEx)project).getStateStore().checkVersion()) {
    return false;
  }

  synchronized (myOpenProjects) {
    if (myOpenProjects.contains(project)) {
      return false;
    }
    myOpenProjects.add(project);
    cacheOpenProjects();
  }
  fireProjectOpened(project);

  final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(project);
  waitForFileWatcher(project);
  boolean ok = myProgressManager.runProcessWithProgressSynchronously(new Runnable() {
    @Override
    public void run() {
      startupManager.runStartupActivities();

      // dumb mode should start before post-startup activities
      // only when startCacheUpdate is called from UI thread,we can guarantee that
      // when the method returns,the application has entered dumb mode
      UIUtil.invokeAndWaitIfNeeded(new Runnable() {
        @Override
        public void run() {
          startupManager.startCacheUpdate();
        }
      });

      startupManager.runPostStartupActivitiesFromExtensions();

      UIUtil.invokelaterIfNeeded(new Runnable() {
        @Override
        public void run() {
          startupManager.runPostStartupActivities();
        }
      });
    }
  },ProjectBundle.message("project.load.progress"),project);

  if (!ok) {
    closeProject(project,true);
    notifyProjectOpenFailed();
    return false;
  }

  if (!application.isHeadlessEnvironment() && !application.isUnitTestMode()) {
    // should be invoked last
    startupManager.runWhenProjectIsInitialized(new Runnable() {
      @Override
      public void run() {
        final TrackingPathMacroSubstitutor macroSubstitutor =
          ((ProjectEx)project).getStateStore().getStateStorageManager().getMacroSubstitutor();
        if (macroSubstitutor != null) {
          StorageUtil.notifyUnkNownMacros(macroSubstitutor,null);
        }
      }
    });
  }

  return true;
}
项目:tools-idea    文件:ModuleStateStorageManager.java   
public ModuleStateStorageManager(@Nullable final TrackingPathMacroSubstitutor pathMacroManager,final Module module) {
  super(pathMacroManager,ROOT_TAG_NAME,module,module.getpicocontainer());
  myModule = module;
}
项目:consulo    文件:BasePathMacroManager.java   
@Override
public TrackingPathMacroSubstitutor createTrackingSubstitutor() {
  return new MyTrackingPathMacroSubstitutor();
}
项目:consulo    文件:MockProjectStore.java   
@Override
public TrackingPathMacroSubstitutor[] getSubstitutors() {
  return new TrackingPathMacroSubstitutor[0];
}
项目:consulo    文件:DirectoryStorageData.java   
public void loadFrom(@Nullable VirtualFile dir,@Nullable TrackingPathMacroSubstitutor pathMacroSubstitutor) {
  if (dir == null || !dir.exists()) {
    return;
  }

  StringInterner interner = new StringInterner();
  for (VirtualFile file : dir.getChildren()) {
    if (!isstorageFile(file)) {
      continue;
    }

    try {
      Element element = JDOMUtil.loadDocument(file.contentsToByteArray()).getRootElement();
      String name = StorageData.getComponentNameIfValid(element);
      if (name == null) {
        continue;
      }

      if (!element.getName().equals(StorageData.COMPONENT)) {
        LOG.error("Incorrect root tag name (" + element.getName() + ") in " + file.getPresentableurl());
        continue;
      }

      List<Element> elementChildren = element.getChildren();
      if (elementChildren.isEmpty()) {
        continue;
      }

      Element state = (Element)elementChildren.get(0).detach();
      JDOMUtil.internStringsInElement(state,interner);
      if (pathMacroSubstitutor != null) {
        pathMacroSubstitutor.expandpaths(state);
        pathMacroSubstitutor.addUnkNownMacros(name,PathMacrosService.getInstance().getMacroNames(state));
      }
      setState(name,file.getName(),state);
    }
    catch (IOException | JDOMException e) {
      LOG.info("Unable to load state",e);
    }
  }
}
项目:consulo    文件:ApplicationStoreImpl.java   
@SuppressWarnings({"UnusedDeclaration"})
public ApplicationStoreImpl(final ApplicationEx2 application,PathMacroManager pathMacroManager) {
  myApplication = application;
  myStateStorageManager =
          new StateStorageManagerImpl(pathMacroManager.createTrackingSubstitutor(),ROOT_ELEMENT_NAME,application,application.getpicocontainer()) {
            private boolean myConfigDirectoryRefreshed;

            @Nonnull
            @Override
            protected String getConfigurationMacro(boolean directorySpec) {
              return directorySpec ? StoragePathMacros.ROOT_CONfig : StoragePathMacros.APP_CONfig;
            }

            @Override
            protected StorageData createStorageData(@Nonnull String fileSpec,@Nonnull String filePath) {
              return new StorageData(ROOT_ELEMENT_NAME);
            }

            @Override
            protected TrackingPathMacroSubstitutor getMacroSubstitutor(@Nonnull final String fileSpec) {
              if (fileSpec.equals(StoragePathMacros.APP_CONfig + '/' + PathMacrosImpl.EXT_FILE_NAME + DirectoryStorageData.DEFAULT_EXT)) return null;
              return super.getMacroSubstitutor(fileSpec);
            }

            @Override
            protected boolean isUseXmlProlog() {
              return false;
            }

            @Override
            protected void beforeFileBasedStorageCreate() {
              if (!myConfigDirectoryRefreshed && (application.isUnitTestMode() || application.isdispatchThread())) {
                try {
                  VirtualFile configDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(getConfigPath());
                  if (configDir != null) {
                    Vfsutil.markDirtyAndRefresh(false,configDir);
                  }
                }
                finally {
                  myConfigDirectoryRefreshed = true;
                }
              }
            }
          };
}
项目:consulo    文件:ProjectStateStorageManager.java   
public ProjectStateStorageManager(final TrackingPathMacroSubstitutor macroSubstitutor,ProjectImpl project) {
  super(macroSubstitutor,project.getpicocontainer());
  myProject = project;
}
项目:consulo    文件:StateStorageBase.java   
protected StateStorageBase(@Nullable TrackingPathMacroSubstitutor trackingPathMacroSubstitutor) {
  myPathMacroSubstitutor = trackingPathMacroSubstitutor;
}
项目:tools-idea    文件:IProjectStore.java   
TrackingPathMacroSubstitutor[] getSubstitutors();
项目:consulo    文件:IProjectStore.java   
TrackingPathMacroSubstitutor[] getSubstitutors();

ios – NSURL:URLByAppendingPathComponent:转换?进入?,但随后UIWebView撤消了转换导致的负载故障

ios – NSURL:URLByAppendingPathComponent:转换?进入?,但随后UIWebView撤消了转换导致的负载故障

我正在加载一个本地html页面并在shouldStartLoadWithRequest中:使用以下url:

... /Library/Application%20Support/CDS/%3Fpid=27ce1ef8-c75e-403b-aea1-db1ae31e05cc/...

在该页面中,如果用户点击链接转到外部网站,则他们点击我的代码处理它的后退按钮:

if ([self.webView canGoBack])
    [self.webView goBack];

但是,当调用[self.webView goBack]后,再次调用shouldStartLoadWithRequest:时,传递给shouldStartLoadWithRequest的URL已更改为:

`... /Library/Application%20Support/CDS/?pid=27ce1ef8-c75e-403b-aea1-db1ae31e05cc/..`.

即OS已经改变了“?”在“?”的URL内.

我从shouldStartLoadWithRequest返回YES:但由于“?”转向 ”?”导致使用WebKitErrorDomain 102调用didFailLoadWithError:并且页面无法加载.

文件实际上有?在它的名字,但它是转换成的iOS系统调用?在构建NSURL对象的过程中,该对象传递给UIWebView:loadRequest:如下所示

NSURL *fullURL = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory                                                                                 inDomain:NSUserDomainMask
                                                                          appropriateForURL:nil 
                                                                                           create: YES
                                                                                               error:&err];

fullURL = [fullURL URLByAppendingPathComponent:folderLocation isDirectory:YES];
fullRUL = [fullURL URLByAppendingPathComponent: pagetoLoad isDirectory:NO];
NSURLRequest *requestObj = [NSURLRequest requestWithURL: fullURL];      
[self.webView loadRequest:requestObj];

folderLocation是一个包含?的Nsstring,对URLByAppendingPathComponent的调用会自动将其转换为?,而不进行该转换,页面加载失败.

有没有人见过这个?

解决方法

我没有使用文件网址,但我遇到了同样的问题.
看起来这是处理它的最佳方式.

Nsstring *newURLString = [[origurl absoluteString] stringByAppendingPathComponent:appendedString];
NSURL *url = [NSURL URLWithString:newURLString];

ios – 带有条件的[NSArray componentsJoinedByString]

ios – 带有条件的[NSArray componentsJoinedByString]

我想使用 – [NSArray componentsJoinedByString],例如:使用“,”连接我的数组的所有元素,除了最后一个我想要“和”的元素.

它python会是这样的:

','.join(array[:-1]) + ' and ' + array[-1]

是否有一种方法或方法可以在一行中完成这一操作,避免所有其他的东西?

解决方法

您可以使用subarrayWithRange:和stringWithFormat:来做同样的事情.如果要检查数组中的项目数,确保您没有索引异常,则至少需要1个.

关于iphone – NSString的stringByAppendingPathComponent:在http://中删除’/’nsstring stringwithformat的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于CGMH:Constrained Sentence Generation by Metropolis-Hastings Sampling解读、com.intellij.openapi.components.TrackingPathMacroSubstitutor的实例源码、ios – NSURL:URLByAppendingPathComponent:转换?进入?,但随后UIWebView撤消了转换导致的负载故障、ios – 带有条件的[NSArray componentsJoinedByString]等相关知识的信息别忘了在本站进行查找喔。

本文标签: